I have the following array:
var items = [
{price1: 100, price2: 200, price3: 150},
{price1: 10, price2: 50},
{price1: 20, price2: 20, price3: 13},
]
I need to get object with sum of all keys like the following:
var result = {price1: 130, price2: 270, price3: 163};
I know I may to use just loop but I'm looking for a approach in underscore style :)
Js from hell:
jsfiddle
For aggregating I'd recommend
reduce
:Or better
Not very pretty, but I think the fastest method is to do it like this
Or, to go really over the top (I think it will can be faster than above one, if you use lazy.js instead of underscore):