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; };