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

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.

主站蜘蛛池模板: 黄石市| 神木县| 饶河县| 龙泉市| 江门市| 九江市| 万荣县| 阿拉善盟| 许昌市| 绥棱县| 凤山市| 建水县| 东阿县| 沁水县| 沐川县| 建宁县| 金平| 安阳县| 裕民县| 高安市| 准格尔旗| 攀枝花市| 夏河县| 修水县| 花垣县| 泸定县| 博野县| 章丘市| 全州县| 洛隆县| 玛纳斯县| 南康市| 江门市| 花垣县| 思茅市| 龙胜| 塘沽区| 北票市| 江山市| 呼玛县| 洛隆县|