Is it possible to use Lodash to sort and group by a specific key (such as "id") and update the values of the elements by adding all unique values of another key (e.g. payout)?
For example, can we take the array below:
[
{
id: 1,
payout: 15,
numOfPeople: 4
},
{
id: 1,
payout: 12,
numOfPeople: 3
},
{
id: 2,
payout: 6,
numOfPeople: 5
},
{
id: 2,
payout: 10,
numOfPeople: 1
}
]
... and transform it into the following using LODASH:
// Note how the payout values have been summed up for each id group
[
{
id: 1,
payout: 27,
numOfPeople: 4
},
{
id: 1,
payout: 27,
numOfPeople: 3
},
{
id: 2,
payout: 16,
numOfPeople: 5
},
{
id: 2,
payout: 16,
numOfPeople: 1
}
]