Logo

Programming-Idioms

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).
New implementation

Type ahead, or select one

Explain stuff

To emphasize a name: _x → x

Please be fair if you are using someone's work

You agree to publish under the CC-BY-SA License

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
/**
 * @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;
}

foo(arry2d);