I'm trying to take this array of nested objects and arrays and return a summed score for the identifier of that specific objects score into a new object. Here is the JSON I'm working with:
{
"AllData" : [ {
"company" : google,
"featureData" : [{
"ScoreTotal" : 10,
"featureName": 'test'
},{
"ScoreTotal" : 10,
"featureName": 'test2'
},
{
"ScoreTotal" : 4,
"featureName": 'test3'
}]
}, {
"company" : amazon,
"featureData" : [{
"ScoreTotal" : 4,
"featureName": 'test'
},{
"ScoreTotal" : 6,
"featureName": 'test2'
},
{
"ScoreTotal" : 3,
"featureName": 'test3'
}]
},{
"company" : facebook,
"featureData" : [{
"ScoreTotal" : 4,
"featureName": 'test' },
{
"ScoreTotal" : 6,
"featureName": 'test2' },
{
"ScoreTotal" : 2,
"featureName": 'test3'
}]
},
}]
}
I'm trying to create an array of objects that have the sum of the score for each unique featureName and the corresponding featureName like this:
[{featureName: 'test1', summedScore: '18'}, {featureName: 'test2', summedScore: '22'},{featureName: 'test3', summedScore: '9'}]
A solution that was close to what I was looking for can be found here, but matching the identifier with the sum was not shown in the solution.
Thank you in advance!
Here's a solution with Ramda