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

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.

主站蜘蛛池模板: 长丰县| 台前县| 景洪市| 湛江市| 会昌县| 运城市| 尉犁县| 新竹县| 玉溪市| 柳江县| 曲阜市| 寻乌县| 定襄县| SHOW| 昭平县| 舒兰市| 谷城县| 迭部县| 汉川市| 成都市| 普格县| 肃宁县| 龙泉市| 江山市| 赤水市| 白河县| 泾川县| 桓仁| 玉田县| 应用必备| 固安县| 托里县| 溧阳市| 泗阳县| 隆昌县| 赞皇县| 四子王旗| 霞浦县| 麻栗坡县| 武安市| 延安市|