Created
February 16, 2011 19:41
-
-
Save dbergey/830017 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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