javascript-in-one-pic icon indicating copy to clipboard operation
javascript-in-one-pic copied to clipboard

the example code for array.reduce can't get the expected result

Open qiaoxingxing opened this issue 6 years ago • 0 comments

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

qiaoxingxing avatar Oct 25 '18 15:10 qiaoxingxing