Skip to content

Instantly share code, notes, and snippets.

@anthonywoodard
Created December 14, 2012 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonywoodard/4288662 to your computer and use it in GitHub Desktop.
Save anthonywoodard/4288662 to your computer and use it in GitHub Desktop.
JavaScript Array Reduce Function
Array.prototype.reduce = function (fn, init) {
var s = init;
var l = this.length;
for (var i = 0; i < l; i++) {
s = fn(s, this[i]);
}
return s;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment