Skip to content

Instantly share code, notes, and snippets.

@IPRIT
Created April 11, 2015 15:18
Show Gist options
  • Select an option

  • Save IPRIT/dd83ed5b077e5d8eae91 to your computer and use it in GitHub Desktop.

Select an option

Save IPRIT/dd83ed5b077e5d8eae91 to your computer and use it in GitHub Desktop.
Example own implemenation of reduce function similar to use Array#reduce
function reduce(arr, fn, prev) {
prev = prev || {};
if (!arr.length) {
return prev;
}
var cur = fn(prev, arr.shift());
return reduce(arr, fn, cur);
}
module.exports = reduce;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment