I have an object with keys as dates in the following format "yyyy-mm-dd" (ex: 2020-08-14)
the value of each key is an array of objects with two attributes, name and value.
I need to find a way to get the sum of the keyvalue grouped by name accros N days.
Here is an example to better understand, the original object have 4 days of data, with one day having an empty array:
{
"2020-10-15":[
{"name":"France","value":20},
{"name":"United States","value":20},
{"name":"Italy","value":5},
],
"2020-10-16":[
{"name":"Germany","value":10},
{"name":"United States","value":5},
{"name":"France","value":10}
],
"2020-10-17":[],
"2020-10-18":[
{"name":"UK","value":10},
{"name":"Italy","value":10},
]
}
For example if we wish to group this data by 4 days we will get the following:
[{"name": "France", "value": 30},
{"name": "United States", "value": 25},
{"name": "Italy", "value": 15},
{"name": "Germany", "value": 10},
{"name": "UK", "value": 10}]
This is the sum of all objects with same value for name across 4 days. I have absolutly no idea how to achieve this, I know can use map to iterate the object keys and do some processing through moment js but I don't know how to achieve this.
.mapor.entriesetc, just create an empty array, start a for loop, and have your code do things the more verbose, much at least understandable-to-yourself way.