I want to reduce an array where the items with the same id have one of their properties summed.
The array would look like this
array = [
{
id: 123,
qty: 10,
unit: 'dollar'
},
{
id: 456,
qty: 15,
unit: 'euro'
},
{
id: 123,
qty: 20,
unit: 'dollar'
}]
With the result being an array that looks like this
array = [
{
id: 123,
qty: 30,
unit: 'dollar'
},
{
id: 456,
qty: 15,
unit: 'euro'
}]
I've been trying to do this with reduce but to no avail.