mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
26 lines
736 B
JavaScript
26 lines
736 B
JavaScript
/**
|
|
* A specialized version of `reduce` for arrays.
|
|
*
|
|
* @private
|
|
* @param {Array} [array] The array to iterate over.
|
|
* @param {Function} iteratee The function invoked per iteration.
|
|
* @param {*} [accumulator] The initial value.
|
|
* @param {boolean} [initAccum] Specify using the first element of `array` as
|
|
* the initial value.
|
|
* @returns {*} Returns the accumulated value.
|
|
*/
|
|
function arrayReduce(array, iteratee, accumulator, initAccum) {
|
|
let index = -1
|
|
const length = array == null ? 0 : array.length
|
|
|
|
if (initAccum && length) {
|
|
accumulator = array[++index]
|
|
}
|
|
while (++index < length) {
|
|
accumulator = iteratee(accumulator, array[index], index, array)
|
|
}
|
|
return accumulator
|
|
}
|
|
|
|
export default arrayReduce
|