In Javascript, if I have an array of arrays representing a matrix, say
x = [ [1,2,3,4], [5,6,7,8], [9,10,11,12] ];
summing it
You could sum the values at the same index.
Use: array.reduce(sum)
array.reduce(sum)
var sum = (r, a) => r.map((b, i) => a[i] + b); console.log([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]].reduce(sum));
.as-console-wrapper { max-height: 100% !important; top: 0; }