Skip to content

Instantly share code, notes, and snippets.

@theptrk
Created April 15, 2017 05:15
Show Gist options
  • Save theptrk/3d4fbf8b4da367c3507877859293c9af to your computer and use it in GitHub Desktop.
Save theptrk/3d4fbf8b4da367c3507877859293c9af to your computer and use it in GitHub Desktop.
// 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