官术网_书友最值得收藏!

The reduce function

The reduce function is a higher-order function that reduces an array to a single value. It takes two parameters: a starting value and a function, which takes a running total and an element of the arrays as parameters and returns a new running total. Consider the following example:

let total = numbers.reduce(0) { $0 + $1 } 

The map, filter, and reduce functions accept a closure as the last parameter, so we were able to use the trailing closure syntax. These higher-order functions will be covered in detail in Chapter 6, Map, Filter, and Reduce.

主站蜘蛛池模板: 大田县| 遂昌县| 榆中县| 澄江县| 定陶县| 铜山县| 灵璧县| 合山市| 朝阳区| 五寨县| 兴国县| 深圳市| 富宁县| 静宁县| 乌兰察布市| 上林县| 蒙阴县| 天峨县| 保靖县| 璧山县| 九寨沟县| 湄潭县| 宁化县| 苏尼特右旗| 上虞市| 吕梁市| 尼勒克县| 酒泉市| 绍兴县| 蒙自县| 扬州市| 介休市| 微博| 兖州市| 建昌县| 扎囊县| 东港市| 和政县| 五大连池市| 大同市| 柘荣县|