I am trying to sort an array of objects based on the sum of one of the object's property. Essentially, like this:
array = [
{
id:4,
tally: [1, 3, 5]
},
{
id: 6,
tally: [2, 3, 6]
},
{
id: 9,
tally: [2, 1, -1]
}
]
If we sum the corresponding tallys, we'd get 9, 11, and 2 respectively, in which case I would like something like this:
array = [
{
id:6,
tally: [2, 3, 6]
},
{
id: 6,
tally: [1, 3, 5]
},
{
id: 9,
tally: [2, 1, -1]
}
]
I know it's some combination of map, reduce but I'm struggling to see how to code it up in the nice proper React format.