I have a collection of array-like objects like this :
a = [[1,2],[3,4],[5,6],[7,8]]
And I would like to sum the columns
(if u think of this as a 4x2 array) such that:
col1_sum = 16
col2_sum = 20
What is the best way of doing this is JS?
I tried using underscore's _.reduce
function like so:
var col1_sum =_.reduce(a, function(memo,obj){ return memo + parseFloat(obj[0]);},0)
but I get an "undefined" error
any ideas? thank you.