Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array.prototype.scan = function (callback, initialValue) {
- const appendAggregate = (acc, item) => {
- const aggregate = acc[acc.length-1] //get last item
- const newAggregate = callback(aggregate, item)
- return [...acc, newAggregate]
- }
- const accumulator = [initialValue]
- return this.reduce(appendAggregate, accumulator)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement