JS application of higher-order functions

Title: obtaining a value greater than 20, then take the following array Total

let nums = [23,45,6,78,8,14]

解答:let newnums = nums.filter(function(n){
return n>20
}).map(function(n){
return n2
}).reduce(function(prevalue,n){
return prevalue+n
})
或者
let newnums = nums.filter(n => n>20).map(n => n
2).reduce((prevalue,n)=> prevalue+n)

                 console.log(newnums)

Guess you like

Origin blog.51cto.com/13550695/2458876