SIGN IN SIGN UP

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

0 0 352 JavaScript
2015-01-08 00:37:01 -08:00
define([], function() {
/**
2015-12-16 17:53:20 -08:00
* A specialized version of `_.reduce` for arrays without support for
* iteratee shorthands.
2015-01-08 00:37:01 -08:00
*
* @private
2016-05-21 00:48:34 -07:00
* @param {Array} [array] The array 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 element of `array` as
* the initial value.
2015-01-08 00:37:01 -08:00
* @returns {*} Returns the accumulated value.
*/
2016-01-24 18:06:10 -08:00
function arrayReduce(array, iteratee, accumulator, initAccum) {
2015-01-08 00:37:01 -08:00
var index = -1,
2016-10-30 20:06:57 -07:00
length = array == null ? 0 : array.length;
2015-01-08 00:37:01 -08:00
2016-01-24 18:06:10 -08:00
if (initAccum && length) {
2015-01-08 00:37:01 -08:00
accumulator = array[++index];
}
while (++index < length) {
accumulator = iteratee(accumulator, array[index], index, array);
}
return accumulator;
}
return arrayReduce;
});