javascript-in-one-pic
javascript-in-one-pic copied to clipboard
the example code for array.reduce can't get the expected result
the example code for array.reduce
can't get the expected result.
in order to get the expected result 0, the second line should change +
to -
.
[55, 44, 33, 22, 11].reduce(function(p, c, i, arr){
//return p + c/(arr. length-i);
return p - c/(arr. length-i);
}, 55); // 0