filter map reduce使用

let numList = [12, 234, 34, 11, 56, 78, 334, 111]

//filter中的回调函数必须返回一个boolean
//true: 但返回的为true时,函数内部会自动吧n加入到新的数组中、
//false: 但返回为false,函数内部会过滤掉这次n
let numLists = numList.filter(n => {
return n < 100
})

let numListc = numLists.map(n => {
return n * 2
})

let numLista = numListc.reduce((privious, n) => {
return privious + n
})

let result = numList.filter(n => {
return n < 100
}).map(n => {
return n * 2
}).reduce((pre, n) => {
return pre + n
})


let total = numList.filter(n => n < 100).map(n => n * 2).reduce((pre, n) => pre + n)

console.log(total)

posted @ 2020-12-18 16:13  Smile浅笑  阅读(57)  评论(0编辑  收藏  举报