Javascript fix mapping dates
Budget: €8 – €30 EUR
I have a "format" array that's used in a map function to return an array of objects with start and end dates.
This format array contains the group of dates that belong to the same object.
let format = [3, 3, 1, 5, 4, 4, 3, 5, 13, 10, 3, 5, 5, 2, 2, 10];
So this way we know the first 3 dates same group, next 3 dates, same group, next date single group date, etc.
My issue/problem: is when there's a group of dates with no-lineal dates (for example 05, 06, 12, 13).
My actual function, is returning an object with
Start: 05
End: 13
But this isn't correct, because we are counting all the days in the middle between 5 and 13. What I would like to do would create two objects for this case:
{
"start": 05,
"end": 06
},
{
"start": 12,
"end": 13
}
In my code, you can see this behavior with the last group of dates (10) (last object).
Is there any way to "check" for the range-dates" before creating the object? Should I add a .map inside the current .map to get 3 sets from the last 10
{
"2022-01-05T04:00:00.000Z", // start
"2022-01-06T04:00:00.000Z",
"2022-01-07T04:00:00.000Z" // end
},
{
"2022-01-10T04:00:00.000Z", // start
"2022-01-11T04:00:00.000Z",
"2022-01-12T04:00:00.000Z",
"2022-01-13T04:00:00.000Z",
"2022-01-14T04:00:00.000Z" // end
},
{
"2022-01-17T04:00:00.000Z", // start
"2022-01-18T04:00:00.000Z" // end
}
Code: https://jsfiddle.net/j6arhs3u/
IMPORTANT: You must provide a valid testing URL (jsfiddle, codepen), before assigning the millestone.
This format array contains the group of dates that belong to the same object.
let format = [3, 3, 1, 5, 4, 4, 3, 5, 13, 10, 3, 5, 5, 2, 2, 10];
So this way we know the first 3 dates same group, next 3 dates, same group, next date single group date, etc.
My issue/problem: is when there's a group of dates with no-lineal dates (for example 05, 06, 12, 13).
My actual function, is returning an object with
Start: 05
End: 13
But this isn't correct, because we are counting all the days in the middle between 5 and 13. What I would like to do would create two objects for this case:
{
"start": 05,
"end": 06
},
{
"start": 12,
"end": 13
}
In my code, you can see this behavior with the last group of dates (10) (last object).
Is there any way to "check" for the range-dates" before creating the object? Should I add a .map inside the current .map to get 3 sets from the last 10
{
"2022-01-05T04:00:00.000Z", // start
"2022-01-06T04:00:00.000Z",
"2022-01-07T04:00:00.000Z" // end
},
{
"2022-01-10T04:00:00.000Z", // start
"2022-01-11T04:00:00.000Z",
"2022-01-12T04:00:00.000Z",
"2022-01-13T04:00:00.000Z",
"2022-01-14T04:00:00.000Z" // end
},
{
"2022-01-17T04:00:00.000Z", // start
"2022-01-18T04:00:00.000Z" // end
}
Code: https://jsfiddle.net/j6arhs3u/
IMPORTANT: You must provide a valid testing URL (jsfiddle, codepen), before assigning the millestone.