1 var arrayReduce = require('../internal/arrayReduce'),
2 baseEach = require('../internal/baseEach'),
3 createReduce = require('../internal/createReduce');
6 * Reduces `collection` to a value which is the accumulated result of running
7 * each element in `collection` through `iteratee`, where each successive
8 * invocation is supplied the return value of the previous. If `accumulator`
9 * is not provided the first element of `collection` is used as the initial
10 * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
11 * (accumulator, value, index|key, collection).
13 * Many lodash methods are guarded to work as iteratees for methods like
14 * `_.reduce`, `_.reduceRight`, and `_.transform`.
16 * The guarded methods are:
17 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
22 * @alias foldl, inject
23 * @category Collection
24 * @param {Array|Object|string} collection The collection to iterate over.
25 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
26 * @param {*} [accumulator] The initial value.
27 * @param {*} [thisArg] The `this` binding of `iteratee`.
28 * @returns {*} Returns the accumulated value.
31 * _.reduce([1, 2], function(total, n) {
36 * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
37 * result[key] = n * 3;
40 * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
42 var reduce = createReduce(arrayReduce, baseEach);
44 module.exports = reduce;