有勇气的牛排博客
☰

es6语法 高阶函数 filter map reduce

有勇气的牛排 1641 前端 2021-11-14 21:02:45

知止自律打卡-微信小程序APP
一款微信自律打卡小程序,支持自定义打卡项目、习惯记录、项目日记、专注计时与数据统计。自律打卡、学习打卡、读书打卡、健身打卡、运动打卡、减肥打卡、戒色打卡、养生打卡、戒烟、戒酒、戒熬夜等多种场景。万能打卡模板自由创建。可自定义每日打卡目标,记录习惯连续天数,可视化追踪成长进度。
了解产品详情 →
微信搜索「知止自律打卡」
知止自律打卡微信小程序
const nums = [10, 20, 30, 100, 200, 40, 50] // 1 filter函数的使用 // let newNums = nums.filter(function (n) { // return n < 100 // }) // console.log(newNums) // 2 map函数的使用 // let new2Nums = newNums.map(function (n) { // return n * 2 // }) // console.log(new2Nums) // 2 reduce函数的使用 // let total = newNums.reduce(function (preValue, n) { // return preValue + n // }, 0) let total = nums.filter(n => n < 100).map(n => n * 2).reduce((pre, n) => pre + n) console.log(total)
// 高阶函数reduce return this.books.reduce(function (preValue, book) { return preValue + book.price * book.count }, 0)

评论区

×
×