js -- 高阶函数的使用
2024-10-08 12:24:54
<!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>
最新文章
- 【皇甫】☀Spring开题中...
- java中数组的相关知识
- caffe中各层的作用:
- objective-c中使用cocoa的NSPredicate,谓词(十四)
- Debian 8 编译安装nginx 1.8
- window下自己主动备份数据库成dmp格式的bat写法
- linux 自动备份脚本
- Cousera课程Learning How to Learn学习报告
- 关于理解python类的小题
- 使用CentOS Linux Bridge搭建Vxlan环境
- NVisionXR引擎基本介绍
- HQL: The Hibernate Query Language
- 计算机网络通信TCP/IP协议浅析 网络发展简介(二)
- 利用朴素贝叶斯分类算法对搜狐新闻进行分类(python)
- Javascript:自己写模板引擎
- 说明Heap与stack的差别。
- 基于Helm和Operator的K8S应用管理的分享
- django static 无法正确加载目录下的css
- [UE4]事件处理(Handling Events)和委托(Delegate)代码示例(二)【C++】
- mybash的编写与调试