Created
July 10, 2018 09:06
-
-
Save loujaybee/60f54c9fbedcae7b4ea5e8f6f49ba73e to your computer and use it in GitHub Desktop.
Basic Reduce Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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