var data = [ {id:1, qty:100}, {id:2, qty:200}, {id:1, qty:100}, {id:2, qty:200} ];
How to sum this array become to [ {id:1, qty:200}, {id:2, qty:
[ {id:1, qty:200}, {id:2, qty:
With Ramda:
Ramda
var f = R.compose( R.values(), R.mapObj(R.reduce(function(a,b) {return {'id': b.id, 'qty':a.qty+b.qty}}, {qty:0})), R.groupBy(R.prop('id')) ); var data = [ {id:1, qty:100}, {id:2, qty:200}, {id:1, qty:100}, {id:2, qty:200} ]; console.log(f(data));
http://jsfiddle.net/4496escu/2/