History of Idiom 195 > diff from v10 to v11
Edit summary for version 11 by aj:
New JS implementation by user [aj]
New JS implementation by user [aj]
↷
Version 10
2021-08-03, 14:32:44
Version 11
2021-08-16, 15:22:40
Idiom #195 Pass a two-dimensional array
Pass an array a of real numbers to the procedure (resp. function) foo. Output the size of the array, and the sum of all its elements when each element is multiplied with the array indices i and j (assuming they start from one).
Idiom #195 Pass a two-dimensional array
Pass an array a of real numbers to the procedure (resp. function) foo. Output the size of the array, and the sum of all its elements when each element is multiplied with the array indices i and j (assuming they start from one).
Variables
a,foo,i,jVariables
a,foo,i,jCode
/**
* @param {Array<Array>} arry
*
* @return {Array<Array>}
*/
function foo(arry) {
let len = 0;
let sum = 0;
arry.forEach(function(base, i) {
len += base.length;
base.forEach(function(a, j) {
sum += a * (i + 1) * (j + 1);
});
});
console.log('Array size:', arry.length, ',', len);
return sum;
}