reduce 函数 可以自动将数组求和,但它内部是如何实现的呢? 今天我们来自己实现一个 reduce 函数
reducer 作用
数组求和
1 | let arr = [1, 2, 3, 4]; |
数组求乘积
1 | let arr = [1, 2, 3, 4]; |
数组求最大(小)值
1 | let arr = [1, 2, 3, 4]; |
当然 还有其他的使用方法
编码实现
1 | Array.prototype.myreduce = function (backcall, grandTotal = 0) { |
reduce 函数 可以自动将数组求和,但它内部是如何实现的呢? 今天我们来自己实现一个 reduce 函数
1 | let arr = [1, 2, 3, 4]; |
1 | let arr = [1, 2, 3, 4]; |
1 | let arr = [1, 2, 3, 4]; |
1 | Array.prototype.myreduce = function (backcall, grandTotal = 0) { |
微信支付
支付宝