Last active
October 9, 2015 00:43
-
-
Save jasonbellamy/896abc68724c85f0258c to your computer and use it in GitHub Desktop.
Imperative sum function that converts the arguments object to an Array.
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
var sum = function () { | |
var result = 0; | |
var args = Array.prototype.slice.call(arguments); // convert arguments into array | |
args.forEach(function(number) { | |
result = result + number; | |
}); | |
return result; | |
}; | |
sum(1, 2, 3, 4, 5); // => 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment