SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 9 JavaScript
2015-01-08 00:37:01 -08:00
define([], function() {
/**
2015-12-16 17:53:20 -08:00
* The base implementation of `_.reduce` and `_.reduceRight`, without support
2016-01-24 18:06:10 -08:00
* for iteratee shorthands, which iterates over `collection` using `eachFunc`.
2015-01-08 00:37:01 -08:00
*
* @private
2015-12-16 17:53:20 -08:00
* @param {Array|Object} collection The collection to iterate over.
2015-01-08 00:37:01 -08:00
* @param {Function} iteratee The function invoked per iteration.
* @param {*} accumulator The initial value.
2016-03-26 00:00:01 -07:00
* @param {boolean} initAccum Specify using the first or last element of
* `collection` as the initial value.
2015-01-08 00:37:01 -08:00
* @param {Function} eachFunc The function to iterate over `collection`.
* @returns {*} Returns the accumulated value.
*/
2016-01-24 18:06:10 -08:00
function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
2015-01-08 00:37:01 -08:00
eachFunc(collection, function(value, index, collection) {
2016-01-24 18:06:10 -08:00
accumulator = initAccum
? (initAccum = false, value)
2015-12-16 17:46:22 -08:00
: iteratee(accumulator, value, index, collection);
2015-01-08 00:37:01 -08:00
});
return accumulator;
}
return baseReduce;
});