Skip to content

Instantly share code, notes, and snippets.

@dbergey
Created February 16, 2011 19:41
Show Gist options
  • Save dbergey/830017 to your computer and use it in GitHub Desktop.
Save dbergey/830017 to your computer and use it in GitHub Desktop.
// Math.sum.apply(null, [3, 4, 5, 6]) => 18
Math.sum = function() {
var total = 0, x = 0;
while (x < arguments.length) total += arguments[x++];
return total;
};
// Math.avg.apply(null, [3, 4, 5, 6]) => 4.5
Math.avg = function() {
return Math.sum.apply(null, arguments) / arguments.length;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment