// filter()过滤函数,map(),reduce()
// 去掉数组中的负数,然后对每一项平方,然后再对每一项翻倍,然后求和
var arr = [1, 2, 3, 4, 5, 6, -1, -2, -3, -4, -5, -6];
var result = arr.filter(function (item) {
return item >= 0;
}).map(function (item) {
return item * item;
}).map(function (item) {
return item * 2;
}).reduce(function(s,item){
return s + item;
});
console.log(result);
JS去掉数组中的负数,然后对每一项平方,然后再对每一项翻倍,求和
猜你喜欢
转载自blog.csdn.net/weixin_45090657/article/details/121254997
今日推荐
周排行