运行结果
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>高阶函数之数组练习</title>
<script src="../js/vuejs-2.5.16.js"></script>
</head>
<body>
</body>
<script>
const arr = [11,52,115,188,68,321,223,64]
let totalFirst = arr.filter(function (n) {
return n<300
}).map(function (n) {
return n*2
}).reduce(function (pre,n) {
return pre + n
},0)
console.log(totalFirst);
let totalSecond = arr.filter( n => n <100).map( n => n*2).reduce((pre,n) => pre+n ,0)
console.log(totalSecond);
</script>
</html>