首页 > Web开发 > 详细

js -- 高阶函数的使用

时间:2020-01-31 22:07:36      阅读:66      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<body>
<div id="app">

</div>
</body>
<script>
    let arr = [1,3,55,8];
    // 需求:arr数组中的所有小于5的值翻倍并求和
    let count = arr.filter(function(n){
        return n < 5;
    }).map(function(n){
        return n*2;
    }).reduce(function(preValue, n){
        return preValue + n;
    },0);
    console.log(`和:${count}`);
</script>
</html>

 

js -- 高阶函数的使用

原文:https://www.cnblogs.com/cl94/p/12246887.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!