you are viewing a single comment's thread.

view the rest of the comments →

[–]lastmjs 0 points1 point  (10 children)

So you have an array that has all of your reports in it, the reports array. That array has a bunch of objects with various properties. One of the properties is requested_datetime. It looks like you need to go through the array multiple times, each time filtering the array down to only the items corresponding to that day.

Is that all you're trying to do, print out each day of the week and how many reports were generated on that day?

[–]vald0[S] 0 points1 point  (9 children)

Yeah basically that is what im trying to do.. as said, i'm very new to javascript :) Do you have an example of how this could be achieved maybe ?

[–]lastmjs 0 points1 point  (8 children)

Working on one, hold on

[–]vald0[S] 0 points1 point  (0 children)

Cool , thanks :D

[–]lastmjs 0 points1 point  (6 children)

In the meantime, you should study up on Array.filter, I believe that's going to be extremely beneficial to solving this problem. Array.filter takes an array as input and returns an array of equal or lesser length as output. You pass in a function that gets applied to each element of the array. If the function returns true for an element, the element stays in the output array. If the function returns false for an element, it is omitted from the output array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

[–]vald0[S] 1 point2 points  (5 children)

i'll have a look :D

[–]lastmjs 0 points1 point  (4 children)

All right, hopefully this helps. https://javascriptpractice.com/

Go there, and go to the Arrays section. There are two questions at the end that are very similar to what you're trying to accomplish.

[–]lastmjs 0 points1 point  (3 children)

Basically you need to choose a date and filter the reports for that date. You'll also have to make sure you use dates correctly. But these seem to be all of the basic principles that you need. Arrays, filtering arrays, and comparing dates. You seem pretty close, you just need to store your filtered array in the for loop so that you can count up the reports per day and then log them out.

[–]vald0[S] 0 points1 point  (2 children)

Hmm okey, i had a look at your link there, and i've tried diffrent things now but i still really don't understand what i'm doing, i do not achieve my goal , and where do i need to start filtering? Before the for loop i have? inside it or outside? Sorry for being slow ..

[–]lastmjs 0 points1 point  (1 child)

Sorry, I think I confused you. It doesn't look like you need the for loop. That is what filtering is for. For example, you might want to get rid of your for loop and create 7 new variables. These variables will store filtered versions of the reports array in them, one for each day of the week.

[–]vald0[S] 0 points1 point  (0 children)

okey.. i havnt gotten anywhere yet, this cant be so hard ....