Please see raw dataset below:
[
{
"date": "2021-12-03",
"minutes": 132.00001,
"category": "RSVR"
},
{
"date": "2021-12-03",
"minutes": 4.95,
"category": "DMND"
},
{
"date": "2021-12-03",
"minutes": 127.03218,
"category": "SLIP"
},
{
"date": "2021-12-04",
"minutes": 113.97533,
"category": "SLIP"
},
{
"date": "2021-12-04",
"minutes": 11.55,
"category": "DMND"
},
{
"date": "2021-12-04",
"minutes": 105.30001,
"category": "RSVR"
}
]
Expected:
would like generate new array where:
- objects with
category: 'DMND'
are added as it is - new object is created using structure (example of new object provided below):
-
{ date: unique date from the objects with category: 'RSVR' and category: 'SLIP' minutes: add minutes from category: 'RSVR' and category: 'SLIP' category: 'SPLY' }
Example { "date": "2021-12-03", "minutes": 132.00001, "category": "RSVR" { }, "date": "2021-12-03", { = "minutes": 259.03219, "date": "2021-12-03", "category": "SPLY" "minutes": 127.03218, } "category": "SLIP" }
(basically merging 2 objects with
category: 'RSVR'
andcategory: 'SLIP'
by adding theirminutes
to create a new object and add that new object to the array) -
New array will look like this:
[
{
"date": "2021-12-03",
"minutes": 4.95,
"category": "DMND"
},
{
"date": "2021-12-03",
"minutes": 259.03219,
"category": "SPLY"
},
{
"date": "2021-12-04",
"minutes": 11.55,
"category": "DMND"
},
{
"date": "2021-12-04",
"minutes": 219.275331,
"category": "SPLY"
}
]
Not quite sure how to go about doing this yet. any help would be appreciated