Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / baseReduce.js
1 /**
2  * The base implementation of `_.reduce` and `_.reduceRight` without support
3  * for callback shorthands and `this` binding, which iterates over `collection`
4  * using the provided `eachFunc`.
5  *
6  * @private
7  * @param {Array|Object|string} collection The collection to iterate over.
8  * @param {Function} iteratee The function invoked per iteration.
9  * @param {*} accumulator The initial value.
10  * @param {boolean} initFromCollection Specify using the first or last element
11  *  of `collection` as the initial value.
12  * @param {Function} eachFunc The function to iterate over `collection`.
13  * @returns {*} Returns the accumulated value.
14  */
15 function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
16   eachFunc(collection, function(value, index, collection) {
17     accumulator = initFromCollection
18       ? (initFromCollection = false, value)
19       : iteratee(accumulator, value, index, collection);
20   });
21   return accumulator;
22 }
23
24 module.exports = baseReduce;