18 lines
352 B
TypeScript
Raw Permalink Normal View History

2024-11-05 10:14:41 +08:00
export function arrayReduce(
array: any,
iteratee: any,
accumulator: any,
initAccum?: any
) {
let index = -1
const length = array ? array.length : 0
if (initAccum && length) {
accumulator = array[++index]
}
while (++index < length) {
accumulator = iteratee(accumulator, array[index], index, array)
}
return accumulator
}