Javascript Array sum(expr)

Description

Javascript Array sum(expr)

Array.prototype.sum = expr => {
  let sum = 0;/*from w w  w .  j  a v a2  s  .co m*/
  this.map(val => (sum += expr ? expr(val) : val));
  return sum;
};



PreviousNext

Related