I am in need of mapping an array consisting of dates. Each date within this array is associated with a group of dates (formatted as an array).
For instance: The format array looks like this:
let format = [3, 3, 1, 5, 4, 4, 3, 5, 13, 10, 3, 5, 5, 2, 2, 10];
This indicates that the first three dates in the dates array belong to one group, the next 3 dates belong to another group, and so on.
Therefore, I expect my output to consist of 16 items (matching the length of the format array). The desired output would look something like this: For the first group of dates: Start: lowest date in that group End: highest date in that group
However, the current output is simply returning entries based on the number of dates.
let format = [3, 3, 1, 5, 4, 4, 3, 5, 13, 10, 3, 5, 5, 2, 2, 10];
let dates = [
// Insert sample dates here
];
var numTimesUsed = 0;
var nameIndex = 0;
let app_multiple = dates.map(function combineTitleData(dataItem, index) {
if (format[nameIndex] == numTimesUsed) {
nameIndex++;
numTimesUsed = 0;
}
numTimesUsed++;
let end = new Date(dates[nameIndex]);
end.setDate(end.getDate() + parseInt(format[nameIndex]) - 1);
return {
start: dates[nameIndex],
end: end
};
});
//
console.log(app_multiple);
Thank you