reduceRight source npm

_.reduceRight(collection, [iteratee=_.identity], [accumulator])

这个方法类似 _.reduce ,除了它是从右到左遍历的。

参数

  1. collection (Array|Object)

    需要遍历的集合

  2. [iteratee=_.identity] (Function)

    这个函数会处理每一个元素

  3. [accumulator] (*)

    初始化的值

返回值 (*)

返回累加后的值

示例

var array = [[0, 1], [2, 3], [4, 5]];

_.reduceRight(array, function(flattened, other) {
  return flattened.concat(other);
}, []);
// => [4, 5, 2, 3, 0, 1]