Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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;
- };
Add Comment
Please, Sign In to add comment