var arr1 = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]];
var arr2 = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]];
var arr3 = [[100, 200, 300, 400], [500, 600, 700, 800], [900, 1000, 1100, 1200]];
var arr4 = [[111, 222, 333, 444], [555, 666, 777, 888], [999, 1110, 1231, 1322]];
var arr1 = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]];
var arr2 = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]];
var arr3 = [[100, 200, 300, 400], [500, 600, 700, 800], [900, 1000, 1100, 1200]];
function summ_array(...arrs){
return arrs.reduce((acc,arr)=>{
if( Array.isArray(arr))
arr.forEach((subarr, i)=>{
if(!Array.isArray(acc[i]))
acc[i] = []
if( Array.isArray(subarr))
subarr.forEach((v, j)=>{
if(!acc[i][j])
acc[i][j] = 0;
acc[i][j]+=v;
});
});
return acc;
},[]);
}
var summ = summ_array(arr1, arr2, arr3);
console.log(summ);
function sum(args, func) {
const result = [];
const length = Math.max(...args.map((item) => item.length));
for (let i = 0; i < length; ++i) {
const arr = args.map((item) => item[i]).filter(Boolean);
const maxLength = Math.max(...arr.map((item) => item.length));
result.push([]);
for (let j = 0; j < maxLength; ++j) {
result[i].push(arr.map((item) => item[j]).filter(Number).reduce(func));
}
}
return result;
}
/* сложить */
sum([arr1, arr2, arr3], (acc, curr) => acc + curr);
/* умножить */
sum([arr1, arr2, arr3], (acc, curr) => acc * curr);