Skip to content

Instantly share code, notes, and snippets.

@ghosthamlet
Forked from omartell/SumAll.js
Created July 17, 2011 14:44
Show Gist options
  • Save ghosthamlet/1087654 to your computer and use it in GitHub Desktop.
Save ghosthamlet/1087654 to your computer and use it in GitHub Desktop.
A function that takes any number of args and returns the sum of them
function sumAll(){
var args = arguments;
if(args.length > 0) {
var element = args[args.length - 1];
var left = Array.prototype.slice.call(args, 0, args.length - 1);
return element + sumAll.apply(window, left) ;
}
else{
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment