Skip to content

Instantly share code, notes, and snippets.

@Ajax30
Created November 23, 2016 19:09
Show Gist options
  • Save Ajax30/2d98493715edf0f3723e84c0542a9b14 to your computer and use it in GitHub Desktop.
Save Ajax30/2d98493715edf0f3723e84c0542a9b14 to your computer and use it in GitHub Desktop.
Add the arguments passed to a function 2
function add(){
// Create an array from the functions arguments object
// then sum the array members using reduce
var sum = Array.from(arguments).reduce(function(a, b){
return a + b;
});
console.log(sum);
}
// You can now add as many numbers as you like
// just by passing them to the function
add(1, 2, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment