I have an array like this
[ { color: 'blue', type: '+', amount: '1' },
{ color: 'blue', type: '-', amount: '1' },
{ color: 'blue', type: '+', amount: '24' },
{ color: 'red', type: '+', amount: '10' },
{ color: 'red', type: '-', amount: '1' },
{ color: 'red', type: '-', amount: '1' },
{ color: 'red', type: '-', amount: '2' } ]
and I would like to group by color and type, and sum the amount. The result should be like this:
[ { color: 'blue', type: '+', amount: '25' },
{ color: 'blue', type: '-', amount: '1' },
{ color: 'red', type: '+', amount: '10' },
{ color: 'red', type: '-', amount: '4' } ]
Is there a good/right way to do this?