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

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.

主站蜘蛛池模板: 太仓市| 特克斯县| 花垣县| 神木县| 海阳市| 城市| 浦东新区| 阿巴嘎旗| 托克逊县| 武功县| 莱西市| 永清县| 岳普湖县| 天台县| 周口市| 阿图什市| 瓦房店市| 江陵县| 黔西县| 阿鲁科尔沁旗| 哈巴河县| 弥勒县| 娄烦县| 德化县| 延津县| 竹山县| 阜南县| 长岭县| 徐汇区| 阳高县| 台中县| 南部县| 昭平县| 慈溪市| 莆田市| 临沂市| 育儿| 浦县| 武强县| 荔波县| 治县。|