Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / collection / reduce.js
1 var arrayReduce = require('../internal/arrayReduce'),
2     baseEach = require('../internal/baseEach'),
3     createReduce = require('../internal/createReduce');
4
5 /**
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).
12  *
13  * Many lodash methods are guarded to work as iteratees for methods like
14  * `_.reduce`, `_.reduceRight`, and `_.transform`.
15  *
16  * The guarded methods are:
17  * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
18  * and `sortByOrder`
19  *
20  * @static
21  * @memberOf _
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.
29  * @example
30  *
31  * _.reduce([1, 2], function(total, n) {
32  *   return total + n;
33  * });
34  * // => 3
35  *
36  * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
37  *   result[key] = n * 3;
38  *   return result;
39  * }, {});
40  * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
41  */
42 var reduce = createReduce(arrayReduce, baseEach);
43
44 module.exports = reduce;