UNPKG

aureooms-js-array

Version:

array manipulation code bricks for JavaScript

34 lines (22 loc) 581 B
/** * Applies the accumulator function iteratively on the * last return value of the accumulator and the next * value in the iterable. The initial value is the initializer * parameter. * * /!\ currently only works with an * accumulator that is a function object * and an array iterable */ export function reduce ( accumulator, iterable, initializer ) { var i, len; i = 0; len = iterable.length; if ( len === 0 ) { return initializer; } for ( ; i < len ; ++i ) { initializer = accumulator( initializer, iterable[i] ); } return initializer; }