Skip to content

Instantly share code, notes, and snippets.

@loujaybee
Created July 10, 2018 09:06
Show Gist options
  • Save loujaybee/60f54c9fbedcae7b4ea5e8f6f49ba73e to your computer and use it in GitHub Desktop.
Save loujaybee/60f54c9fbedcae7b4ea5e8f6f49ba73e to your computer and use it in GitHub Desktop.
Basic Reduce Implementation
Array.prototype.reduceLou = function( func, start = 0 ){
let state = start;
for(let i = 0; i < this.length; i++) {
state = func(state, this[i]);
}
return state;
}
console.log([1, 2, 3].reduce((prev, item) => prev + item ))
console.log([1, 2, 3].reduceLou((prev, item) => prev + item ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment