Created
April 15, 2017 05:15
-
-
Save theptrk/3d4fbf8b4da367c3507877859293c9af to your computer and use it in GitHub Desktop.
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
// write reduce without Array.reduce | |
// @param {Array} list | |
// @param {Function} fn takes (acc, result) | |
// @acc {*} acc is the starting point or working accumulator | |
const reduce (list, fn, acc) => { | |
let i = 0; | |
var len = list.length; | |
while(i < len) { | |
acc = fn(acc, list[i]) | |
} | |
return acc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment