JSFiddle - React, Tailwind, and code Playground
JavaScript
var arr = [[1,2,3],[1,3,2],[1,1,1],[1,2,3],[1,3,2],[1,1,1]];
function compute1(arr) {
var reduce = function (index, array) {
return _.reduce(arr, function(acc, array) {
acc += array[index];
return acc;
},0);
}
return _.map([0, 1, 2], reduce);
};
function compute2(arr) {
var reduce = function (index, array) {
return _.reduce(arr, function(acc, array) {
acc += array[index];
return acc;
},0);
}
return [reduce(0), reduce(1), reduce(2)];
};
function compute3(arr) {
var reduce = function (index, array) {
return _.reduce(arr, function(acc, array) {
acc += array[index];
return acc;
},0);
}
var X = reduce(0);
var Y = reduce(1);
var Z = reduce(2);
return [X,Y,Z];
};
console.log(compute1(arr));
console.log(compute2(arr));
console.log(compute3(arr));