Trying to create a compound object in map but stuck at a point. map over an array which has start and end time and some event. below is code.
let detailsRes = Object.create({});
response.map((res, i) => {
let start = new Date(moment(res.startTime).format('L'));
let end = new Date(moment(res.endTime).format('L'));
let current = new Date(start);
while (current <= end) {
date = [new Date(current).getFullYear(), new Date(current).getMonth() + 1, new Date(current).getDate()].join('-');
detailsRes[date] == undefined ? (detailsRes[date] = 1) : (detailsRes[date] += 1);
var newDate = current.setDate(current.getDate() + 1);
current = new Date(newDate);
}
});
sample data
[{
"endTime": "2020-12-06 16:30:00.000Z",
"event": "Study",
"startTime": "2020-12-06 12:30:00.000Z",
'somedata':'js is good'
},
{
"endTime": "2020-12-06 16:30:00.000Z",
"event": "gym",
"startTime": "2020-12-05 12:30:00.000Z",
'somedata':'js is good'
},
]
current output
{5-12-2020 : 1, 6-12-2020 : 2 },
expected output
5-12-2020 : {
totalcount: 1, // 5 is only 1 time
event1: 1 //gym
},
6-12-2020 : {
totalcount:2, // 2 times 6-12 is there so count is 2
event1: 1, //gym
event2: 1 // study
}
so basically checking how many events are coming between dates, if event is between 1-12 to 3-12 then individual object of 1,2,3 and totalcount of 1 for each date and if any other events coming in between then increment that particular totalcounts. above given output of mine which is correct but trying to modify object like expected output. so i need this kind of object.
7-12-2020) be created?event1:1andevent2:1refer to? is there just a new keyeventNfor every event always with the value1? Can there beevent1:2if so how?