reduceRight.js 957 B

1234567891011121314151617181920212223242526272829
  1. var arrayReduceRight = require('../internal/arrayReduceRight'),
  2. baseEachRight = require('../internal/baseEachRight'),
  3. createReduce = require('../internal/createReduce');
  4. /**
  5. * This method is like `_.reduce` except that it iterates over elements of
  6. * `collection` from right to left.
  7. *
  8. * @static
  9. * @memberOf _
  10. * @alias foldr
  11. * @category Collection
  12. * @param {Array|Object|string} collection The collection to iterate over.
  13. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  14. * @param {*} [accumulator] The initial value.
  15. * @param {*} [thisArg] The `this` binding of `iteratee`.
  16. * @returns {*} Returns the accumulated value.
  17. * @example
  18. *
  19. * var array = [[0, 1], [2, 3], [4, 5]];
  20. *
  21. * _.reduceRight(array, function(flattened, other) {
  22. * return flattened.concat(other);
  23. * }, []);
  24. * // => [4, 5, 2, 3, 0, 1]
  25. */
  26. var reduceRight = createReduce(arrayReduceRight, baseEachRight);
  27. module.exports = reduceRight;