I have a pretty difficult situation and I'm not sure how to convert it using lodash and the moment. Let's say that I have a date range and this source data.
var startDate = "2018-02-21"
var endDate = "2018-02-23"
var data = [
{
"date": "2018-02-21 21:21:17",
"group": "A"
},
{
"date": "2018-02-21 21:21:17",
"group": "B"
},
{
"date": "2018-02-23 21:21:17",
"group": "A"
},
{
"date": "2018-02-21 21:21:17",
"group": "B"
}
];
I would like to use lodash to group all the "group" fields and a new field in a new object named "date", which will be a key / date value pair. The keys will be a date range (from startDate to endDate), and the values will be the number of matching dates.
The new output will look like this:
var output = [
{
"group": "A",
"dates": [
"2018-02-21": 1,
"2018-02-22": 0
"2018-02-23": 1
]
},
{
"group": "B",
"dates": [
"2018-02-21": 2,
"2018-02-22": 0,
"2018-02-23": 0
]
}
];
I created jsfiddle and imported the moment and lodash of this situation.
http://jsfiddle.net/dp7rzmw5/6467/
Thank you so much if you can help!
source
share