const nums = [10,20,111,222,444,40,50]
let funcTotal = nums.filter(function (n) {
return n < 100
}).map(function (n) {
return n * 2
}).reduce(function (pre,n) {
return pre + n
},0)
console.log('funcTotal ' + funcTotal);
//使用箭头函数
let arrowTotal = nums.filter(n => n< 100).map( n => n *2 ).reduce((pre,n) => pre + n)
console.log("arrowTotal " + arrowTotal);
网友评论