JavaScript中分别用数组forEach()、reduce()方法求数组元素的和
function sum(arr) { let count=0; arr.forEach(function(x){ count+=x; }) return count; }
function sum(arr) { return arr.reduce((a,b)=>a+b,0); }
function sum(arr) { let count=0; arr.forEach(function(x){ count+=x; }) return count; }
function sum(arr) { return arr.reduce((a,b)=>a+b,0); }