I'm trying to group the following array of objects by the key amount_per_btc
where the values are the same, and then sum the values of the key btc_qty
.
Below is the ungrouped sample.
[ { amount_per_btc: 2600000, btc_qty: 0.001 },
{ amount_per_btc: 2600000, btc_qty: 0.001 },
{ amount_per_btc: 2600000, btc_qty: 0.001 },
{ amount_per_btc: 150000000, btc_qty: 0.001 },
{ amount_per_btc: 150000000, btc_qty: 0.01 },
{ amount_per_btc: 150000000, btc_qty: 0.001 } ]
My result should look like this:
[ { amount_per_btc: 150000000, btc_qty: 0.012 },
{ amount_per_btc: 2600000, btc_qty: 0.003 }]
I'm using nodejs so a pure javascript or lodash solution will be appreciated.