Skip to content

Instantly share code, notes, and snippets.

@jasonbellamy
Last active October 9, 2015 00:43
Show Gist options
  • Save jasonbellamy/896abc68724c85f0258c to your computer and use it in GitHub Desktop.
Save jasonbellamy/896abc68724c85f0258c to your computer and use it in GitHub Desktop.
Imperative sum function that converts the arguments object to an Array.
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