« first day (3309 days earlier)      last day (1629 days later) » 
00:00 - 20:0020:00 - 23:00

12:02 AM
I guess if you ask question it might give you more chance
 
-1
Q: How can I format my array of objects in javascript?

KyleNeed to format my array of objects to have a nested object. Tried using map, and reduce. Can't seem to get the formatting correct. Currently getting this. [ { "date": "2019-10-01T00:00:00Z", "total": 20 } ] Need it to be in this format. [ { name: 'Total Call Volume', da...

 
var mapData = arr.map(item => ({
  date: item.startTime,
  total: item.dataValues.TOTAL_CALL_VOLUME
}));
here is how you compose your object
after you format it you will need to adjust reduce function as well
 
yeah the reduce part is what im stuck on
 
well should be dead simple
  {
    name: 'Total Call Volume',
    data: {
      '2019-01-01 00:00:00 -0800': 0,
      '2019-01-01 00:00:00 -0800': 88,
    }
  }
 
That's how I want it to look, but the output of my reduce function doesn't work
 
12:10 AM
I use it for reference
not to jump around tabs
 
oh sorry
 
do you know how map works?
 
Yeah i think so
 
you just need to adjust this part
.map(d => ({ id: d[0] + ':' + d[1] }) );
you can go for more simple solution
wrap your results with objects
 
var data = mapData.reduce((obj, item) => {
        obj.data[item.date] = item.total;
        return obj,
        {
          name: 'Total Call Volume',
          data: {}
        }
      })
 
12:13 AM
@Kyle Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq.
 
to use variable as a key in js you can do

{[d[0]]: d[1]}
 
Can anyone help me with React please?
 
this will give you "'2019-01-01 00:00:00 -0800': 0,"
as object
from there you can wrap that thing
 {
    name: 'Total Call Volume',
    data: variable representing your stuff goes here
  }
@storagemode11 what is the issue
 
It will take so much to explain, can we go to private chat please?
 
just start it
 
12:16 AM
How..?
 
not exactly sure how to wrap it
 
@Kyle create object with desired format
add your values ar value for your key
 
everything i've tried hasn't worked, would you be able to post a snippet of what you mean?
 
 
3 hours later…
3:00 AM
@KarelG totally correct lol
 
 
4 hours later…
7:29 AM
hi there
 
7:47 AM
hello
 
hello
 
@JAYPATEL Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
Can someone suggest how to output same log when running webpack but using compiler.run() ?
 
8:24 AM
@Raimonds is that not just using the .log hook ?
hmm lemme dig in documentation because it has been a while
 
someone wrote a whole chatroom using purely the console log of a browser
thought that was a cool idea
 
Hi Neil.
Had an MC so was off work.
 
hola, Hassan
 
                        function displayRange(current, max) {
				if (current > max)
					return;

				console.log(current);

				current++;
				displayRange(current, max);
			}

			displayRange(10, 10);
I did this btw, but couldn't show you.
That good? Or can be improved?
Works (ofc)
 
there you go, you got it
 
8:28 AM
I can do simple stuff, but cant do complicated ones
You can give me something thats a bit more challenging?
 
@KarelG Have no idea, I rewrote whole webpack.config.js file we were using to go for more programmatic approach, before we used cmd "webpack --mode=production", now we use "node webpack.config.js" which then creates instance of compiler and we just run it, however console output is different, I think I have all stats not formated version with info I used to
 
@HassanAlthaf hmm, ok, how about you write a recursive function which writes all prime numbers up to a max
 
there are occasional programming challenges on the web.
 
8:30 AM
you must do so efficiently as well, it isn't enough to check if each individual number is prime
 
some mathematicians would like have a word with you
 
keep track of all prime numbers up until that point, and use that to your advantage
 
I have a dynamic field which enables only when I select particular option from dropdown. After adding all the other field values there is add address button by clicking on which a new page opens. Now when I save address then I return back to previous page which has dynamic field at that time all the other fields retains their values(cache value) but not this dynamic value.
what can be done to solve this problem?
 
3 mins ago, by Neil
keep track of all prime numbers up until that point, and use that to your advantage
the way you did it is inefficient
you're literally calculating all primes from 0 to i for every i from 0 to max
 
8:35 AM
You men for repeated calsl?
mean*
 
yes, this works, but it isn't effiicent
 
So, it doesn't calculate again?
 
once you know all prime numbers from 2 to n, you should be able to know rather efficiently if n + 2 is a prime
if you don't keep that information, then you calculate all primes from 2 to n every time
 
you mean like
if i do 2-20.
then i wanna know if 22 is prime or not?
or, 2-22?
 
there are rules about prime numbers
eg it can be only divided by 1 and itself.
but you can fasten the progress by skipping even numbers after 2
 
8:40 AM
yes, thats why i skipped those in my loop, any other number, cannot be divisible, for that i have a flag
Oh.
 
well that's a trivial optimization
What I'm talking about is keeping a running list of all primes, and using that to determine the next prime
 
That would be a different function
 
this is way faster than determining the next prime without knowing what primes come before it
 
Or within itself?
 
why would it be a different function? It performs the same end result
 
8:41 AM
Alright, so you want basically
0-20 firstt, stores the result.
Maybe then I do 10-25, it will make use of the results
and calculate the next?
 
@Neil that's another way to fasten the process
there are more tho :P
I know other 2
 
@KarelG well effectively that would half the time
what I was thinking of will reduce it by Phi
Actually Phi*n
where Phi is the golden ratio
 
I know Phi. Do you want to know it?
abhor Phi*n
 
Wow, that stuff is hardert
than I thought
keeping track of others
is easy,
but making use isnt
 
how do I append nested elements to formdata();
{
  "CandidateMode": "",
  "TitleId": "",
  "LstEmployeeDocs": [{
      "FieldId": "14",
      "FieldName": "FirstName",
      "DocumentPath": {
        "lastModified": 1517220427699,
        "lastModifiedDate": "2018-01-29T10:07:07.699Z",
        "name": "abc.PNG",
        "size": 1793731,
        "type": "image/png"
      }
    },
    {
      "FieldId": "16",
      "FieldName": "LastName",
      "DocumentPath": {
        "lastModified": 1517220427699,
        "lastModifiedDate": "2018-01-29T10:07:07.699Z",
I'm sending this data to c# controller through ajax
 
8:52 AM
"nested elements" = .... ?
if you want to add items to your formData object, you can simply use .append
 
@KarelG nested objects
 
well, just add it with that .append
 
var form_data = new FormData();
for (var key in employeeViewModel) {
    form_data.append(key, employeeViewModel[key]);
}
 
@AbhishekPandey Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq.
 
that should work, but it depends of what employeeViewModel is at that moment
 
8:55 AM
@KarelG above data is the employeeViewModel but append is not appending array part to DocumentPath
@JamesBot Sure
 
@Neil I'll look at it once I am done with my attempt
I'm almost done
 
study that. That isn't what you're supposed to do, as this finds the next prime given all previous primes.
but you should be able to use that to make a recursive function
 
@KarelG in controller I'm getting empty array, another option I have tried is to stringify array but that makes hard to parse it into c#
 
are you sure that the formdata array is empty?
check your request (in network tab)
 
9:00 AM
actually there was an error :P Use the updated link
 
if it is there, then look at the server for your problem
 
@KarelG if it wasn't I haven't asked here :D
 
add .append('LstEmployeeDocs[]', thatJsArray); manually
 
Is that what you meant
 
@HassanAlthaf no!
no global variables!
make it work without
 
9:03 AM
@KarelG you always have been my life saver, let's hope this time history stays the same :D
 
@Neil ... @ that for(prime in primes)
IMA SPEECHLESS
 
@Neil Well.. you already gave me the code... lol
I didn't know can't use global vars xD
because u wanted to store the state
 
@KarelG do I need to pass index in array?
 
index? o.O
 
clearly i didn't understand the question well, my bad.
 
9:06 AM
it just accepts an array, no?
 
append('LstEmployeeDocs[0]', thatJsArray);
append('LstEmployeeDocs[1]', thatJsArray);
?
 
@KarelG what's wrong with that? :P
 
@Neil You're such a genius
I wish I had a brain like yours.
 
@HassanAlthaf I didn't specify, you're right. Though you should avoid global variables always unless explicitly told otherwise
 
@Neil two things :/
 
9:09 AM
@KarelG prime and primes?
 
@Neil Oh.
 
no
1. doing for(prime in primes) makes prime global.
add a const beforehand
2. use for...of instead of for...in which is WRONG. BAD. FOR-IN IS BAD
 
why is for in bad?
also you're right about #1
 
it goes through all enumerable properties
 
LstEmployeeDocs[]: [object Object]
LstEmployeeDocs[]: [object Object]
 
9:11 AM
oh? including non-numbers?
 
for...of only goes through iterable objects that is being defined to be iterated over
 
isn't prime
the index of the current element in primes?
shouldn't the code be primes[prime]
 
I got these in network, a hope
 
@AbhishekPandey how are you assigning to it?
 
for(const i in [1,2,3,4,0]) console.log(i);
 
9:13 AM
seems a toString call which should not occur
 
this returns the same as:
for(const i of [1,2,3,4,0]) console.log(i);
 
do it again when a stupid embodiment has decided to do this
const arr = [1,2,3,];
arr.max = 100;
go through it
 
@HassanAlthaf "prime" should be the actual value of the prime number and not the index
 
Though KarelG makes a good point.
 
9:14 AM
for(prime in primes) {
    	if(nextPossiblePrime % primes[prime]== 0) {
      	found = false
        break;
      }
    }
primes[prime]
 
oh no
 
oh wow, totally wrong today
 
@KarelG like this, an empty array
 
@HassanAlthaf good catch
 
9:16 AM
i know this because i made the same mistake and had a wtf moment
 
do:  for(const prime of primes)
prime being the value (not index)
 
yup.
man teach me, you're a pro. be my mentor plsss
give me challenges to complete.
Neil and Karel, you both so pro
 
solve that one
should be easy enough
though make it so that it will also work for n=200 :)
 
I don't quite get that question
 
I have a question for TensorFlow.js. Does the model.fit function require you to use two-demsional tensors as the first and second arguments? And why can't model.predict accept scalars as their argument?
 
9:19 AM
Sorry, kinda been a while since I did high school math LOL
 
@HassanAlthaf 4! is 4 * 3 * 2 * 1 or 24
If I put in 4, I want you to print out the last digit of 24, so 4
 
the problems on kattis often aren't described properly
 
Oh....
 
But it should also work for 200.. any number really
can't really use recursion for levels more than say 50
but you could also create a recursive version that would work for smaller values of n
 
9:22 AM
200 ! =
undefined
JS can't handle that number?
googled that
 
@KarelG append('LstEmployeeDocs', thatJsArray); is also working
you saved it :D
 
@HassanAlthaf ah ha, that's part of the challenge isn't it? :P
javascript can't represent 50!, much less 200!
I mean I think it can give you a result, but it wouldn't keep track of the first digit anymore
 
@HassanAlthaf Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
 
                                function lastDigitOfFactorial(n, current, total) {
				if (n < 0)
					return "Un-defined";

				total = total || 1;

				if (n >= 0 && n < 2) {
					return total;
				}

				current = current || 2;

				if (current > n) {
					return console.log(total % 10);
				}

				total *= current;
				current++;

				lastDigitOfFactorial(n, current, total);
			}

			lastDigitOfFactorial(50);
Does for 50!
 
Yeah, pretty sure that's wrong
 
9:34 AM
It's right. But doesn't for 200!
NaN
You're right. It shouldn't work.
But it magically is.
                                if (!Number.isSafeInteger(total)) {
					console.log(current);
				    }
Prints every number after 19.
Nevermind.
if (test > Number.MAX_VALUE) {
console.log(current);
}
Throws up at 171
 
@AbhishekPandey tbh, if a parameter is an array, it should be denoted as it is. But whelp
 
@Neil is my program wrong
 
@HassanAlthaf yep, pretty sure it is
@HassanAlthaf what do you get when you pass in 4?
what do you expect it would do? What does it do instead?
you should be able to determine if your function isn't correct
I already gave the case of 4, where 4 * 3 * 2 * 1 is 24, and the last digit is 4
so you should be getting 4
 
10:04 AM
@KarelG I yeah, I had to roll it back to []
 
 
4 hours later…
1:49 PM
finally
sometimes I make a mistake. When fixing it, I could not assign anymore because identifier already declared
 
2:27 PM
hi
 
2:38 PM
Hello, maybe someone here can help me... how to update a json list and directly setState in react because of a missing key property ?

my code so far
this.setState(prevState => ({ShopDataList: []}))
res.data.map((ShopData, index) => {
ShopData.key = index
this.setState(prevState => ({
ShopDataList: [...prevState.ShopDataList, ShopData]
}))

but erro is allways "Uncaught (in promise) TypeError: Cannot read property 'map' of undefined"
 
@CrissCrossCrass Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
 
@CrissCrossCrass res.data is undefined then
 
hmm but if make right before console.log(res.data); i have a array with 2 json data inside
 
then either it's a race condition, happening elsewhere, or you didn't properly perform the test
 
axios.get("http://localhost:8080/api/something").then(res => {
            console.log("Received Successful response from server!");
            console.log(res.data);
            this.setState(prevState => ({ShopDataList: []}))
            res.data.map((ShopData, index) => {
              ShopData.id = index
              this.setState(prevState => ({
                ShopDataList: [...prevState.ShopDataList, ShopData]
              }))
            },);

    }
is nothing more here :o oh man
maybe my map using is wrong.. ?
 
2:47 PM
lol im an idiot... I finally found how to make DOM Commands
like prototype methods (.Name();)
Converting all my trashy dat.gui tools into web APIs that are dynamic
 
:4778408 honestly, it doesn't look wrong to me
whatever it is, it is well hidden
 
Neil, have you ever used prototype methods?
Im actually trying to look for a list of all the selectors.
Element.prototype.NAME = function() {
like that allows you to select element objects
 
@TaylorS you probably shouldn't be using prototype :P
 
using the Element Object... do you know of a list of all these prototype objects
Neil, dont all the Libraries use them?
like all the web-apis
Like jQuery?
Or am I a complete idiot
I just wanted to use prototype so I could make things like this:
Element.prototype.cetPNG = function() {
 var w = window.open("", "PNG");
 var f = this.toDataURL("image/png");
 w.document.write(
  "<div><a href='" +
   f +
   "' download='Canvas Image'><img src='" +
   f +
   "' alt='from canvas'>PNG</img></a></div> "
 );
};
This allows you to write document.getElementById('canvas').cetPNG();
and it saves it as a png file.
Neil??
 
3:12 PM
Hello.
Anyone there?
 
3:26 PM
@Neil okay found the issue, it was really well hidden in somewhere else :t
@Neil anyway thanks!
 
@CrissCrossCrass ah ha! :)
told ya
 
Neil
you said I shoudlnt use prototype... got an alternative?
I need a way to make dynamic methods, and so far, prototype is the only way I know how
 
@TaylorS elements can hold data without requiring the use of prototypes
functions can take elements as parameters
you don't need anything else
 
yes, I know
but I want to make simple jQuery-like methods like this: ".method();"
rather than needing: "functionName(arguments);"
 
@TaylorS ok, well just saying you don't have to :)
you know there are alternatives though
 
3:38 PM
Thats what im asking
what are the alternatives :L
 
rather than have a function using "this" where this is the element, you simply pass the element as a parameter. Period.
don't try to get fancy
you don't need to have them chainable
 
user12053089
3:57 PM
Element.prototype.cetPNG = function() {
 let window = window.open("", "PNG");
 let file = this.toDataURL("image/png");
 window.document.write(
  "<div><a href='" +
   file +
   "' download='Canvas Image'><img src='" +
   file +
   "' alt='from canvas'>PNG</img></a></div> "
 );
};
 
@Morpheus Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
@Morpheus Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
user12053089
what is this -> Element?
 
4:28 PM
Something with a prototype
 
user12053089
lol i meant give me a description of what they mean by element
 
/What do you mean what they mean by element?
 
user12053089
in order words naming conventions
 
it's clearly some kind of object
 
user12053089
why is it called elelment?
 
4:29 PM
Probably because of what it is
 
user12053089
its bad practice and unclear
 
user12053089
element of what?
 
What is Element?
 
user12053089
its abstract
 
maybe so, but maybe because what it's representing is also abstract.
 
user12053089
4:30 PM
its silly
 
user12053089
its a link to a file
 
i can't agree with you without knowing what "Element" is
 
user12053089
its not a design
 
user12053089
exactly my point
 
if Element is a dom node
it makes perfect sense
 
user12053089
4:31 PM
no its doesnt
 
user12053089
its non descript
 
by design
because it can represent any element
 
user12053089
its could be an element of the periodic table
 
|| mdn Element
 
no, it cannot
 
@Morpheus ^
 
user12053089
yes it can
 
user12053089
its not descript
 
No, it cannot
lol
 
user12053089
yes it can
 
4:32 PM
context matters
 
It describes a DOM element
 
user12053089
yes it does
 
user12053089
terrible practice
 
No
 
user12053089
yes
 
4:32 PM
Element is an element. how is that a bad name?
 
user12053089
element can apply to many things
 
user12053089
including web design
 
user12053089
it could be anything
 
Well guess what
 
user12053089
its bad design and you agreeing with it speaks volumes
 
4:33 PM
its only available on the web
so there you go
if you work in node that object doesn't exist
 
It only exists where the DOM Api is present.
 
@Morpheus I'm not agreeing. I am disagreeing.
@Morpheus if you hate it so much don't use it
 
@JBis It's also a thing, but presumably Thing would be a bad name
 
I can't tell if you are agreeing or disagreeing lol
 
Element could be an appropriate name, I'd need more context to be sure. I just didn't agree with the logic of "Element is an element therefore 'Element' is a good name"
 
4:42 PM
This is a really dumb and pointless argument
 
Yeahh
 
5:00 PM
Hope you guys can help me out with a quick question: Does Firefox not support OffscreenCanvas or is there an issue on my end?
 
@TuxStash.de Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
Does anyone know how to use Vue transitions to put an expand/collapse transition on table rows?
0
Q: How to use Vue height transitions on a table row

HypersapienI have a treeview table generated in Vue with buttons to expand and collapse an item's children. I'm trying to figure out how to set up Vue transitions so that when sections expand and collapse, their height animates from and to the natural height of the row to zero. I've tried several solution...

 
@DanMandel Totally overlooked that chart. Thanks :D
The funny thing is, when I was looking to optimize my canvas, I got the idea from the MDN and expected it to work on Firefox, but just tested on Chrome.
 
 
2 hours later…
7:01 PM
1 message moved to Trash can
 
@Neil
The outputs look correct tbh
 
7:38 PM
Hi, guys. Can anyone recommends me the best lib to work with authentication JWT. I was trying use Passport, but i'm getting stuck with its doc.
 
@Dener Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
7:53 PM
passport is the only one i'd suggest
 
00:00 - 20:0020:00 - 23:00

« first day (3309 days earlier)      last day (1629 days later) »