Skip to content

Instantly share code, notes, and snippets.

@ehrenmurdick
Created December 15, 2010 19:01
Show Gist options
  • Save ehrenmurdick/742425 to your computer and use it in GitHub Desktop.
Save ehrenmurdick/742425 to your computer and use it in GitHub Desktop.
$.extend(Array.prototype, {
inject: function(aggregate, iterator) {
$(this).each(function() {
aggregate = iterator(aggregate, this);
});
return aggregate;
},
sum: function() {
return this.inject(0, function(aggregate, item) {
return aggregate + item;
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment