Let\'s say that I have an array of arrays, like so:
[ [0, 1, 3], [2, 4, 6], [5, 5, 7], [10, 0, 3] ]
How do I generate a new array t
One-liner in ES6, with map and reduce
ES6
map
reduce
var a = [ [0, 1, 3], [2, 4, 6], [5, 5, 7], [10, 0, 3] ]; var sum = a[0].map((_, i) => a.reduce((p, _, j) => p + a[j][i], 0)); document.write(sum);