Skip to content

Instantly share code, notes, and snippets.

@khamiltonuk
Created June 11, 2014 07:58
Show Gist options
  • Select an option

  • Save khamiltonuk/0eae34869ffff7ac0eb0 to your computer and use it in GitHub Desktop.

Select an option

Save khamiltonuk/0eae34869ffff7ac0eb0 to your computer and use it in GitHub Desktop.
Adding and subtracting all the arguments in a function
function sum(){
var result = 0,
i = 0,
len = arguments.length;
while (i < len){
result += arguments[i];
i++;
}
return result;
}
function takeaway(){
var result = arguments[0],
i = 1,
len = arguments.length;
while (i < len){
result -= arguments[i];
i++;
}
return result;
}
console.log(takeaway(1,3,2,2,4,1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment