Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. Array.prototype.scan = function (callback, initialValue) {
  2. const appendAggregate = (acc, item) => {
  3. const aggregate = acc[acc.length-1] //get last item
  4. const newAggregate = callback(aggregate, item)
  5. return [...acc, newAggregate]
  6. }
  7.  
  8. const accumulator = [initialValue]
  9.  
  10. return this.reduce(appendAggregate, accumulator)
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement