I have the following array:
[
{
"idItem": "5d656f10394d6524c821f1b1",
"mark": 5,
"date": "2018-11-27T00:00:00.000Z"
},
{
"idItem": "5d656f10394d6524c821f1b1",
"mark": 2,
"date": "2018-11-27T00:00:00.000Z"
},
{
"idItem": "5d656f10394d6524c821f1b1",
"mark": 1,
"date": "2018-12-27T00:00:00.000Z"
},
{
"idItem": "5d656f10394d6524c821f1b1",
"mark": 2,
"date": "2018-12-27T00:00:00.000Z",
}
]
And i want to merge the object based on idItem and date and calculate the average mark so i can have the following:
[
{
"idItem": "5d656f10394d6524c821f1b1",
"mark": 3.5,
"date": "2018-11-27T00:00:00.000Z"
},
{
"idItem": "5d656f10394d6524c821f1b1",
"mark": 1.5,
"date": "2018-12-27T00:00:00.000Z"
}
]
3.5for the first object in the result?