Urara-Blog/node_modules/.pnpm-store/v3/files/66/e5dfecc751409dd73eafcc82bfda41de3f327a992987553dfeff315ad83a539d3bc1d91bdc4b7f3a9f93288dc758565d4ec46f34784b97a75ae0a1a29dc16b
2022-08-14 01:14:53 +08:00

23 lines
909 B
Text

/**
* The base implementation of `_.reduce` and `_.reduceRight`, without support
* for iteratee shorthands, which iterates over `collection` using `eachFunc`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} accumulator The initial value.
* @param {boolean} initAccum Specify using the first or last element of
* `collection` as the initial value.
* @param {Function} eachFunc The function to iterate over `collection`.
* @returns {*} Returns the accumulated value.
*/
function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
eachFunc(collection, function(value, index, collection) {
accumulator = initAccum
? (initAccum = false, value)
: iteratee(accumulator, value, index, collection);
});
return accumulator;
}
module.exports = baseReduce;