SHARE
TWEET

Untitled

a guest Oct 13th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top