Skip to content

Instantly share code, notes, and snippets.

@svahora
Created August 9, 2015 18:22
Show Gist options
  • Save svahora/d1ced732c9cf57fb79b3 to your computer and use it in GitHub Desktop.
Save svahora/d1ced732c9cf57fb79b3 to your computer and use it in GitHub Desktop.
function add() {
//if any given value is not a number it will return udefined
for (var i = 0; i < arguments.length; i++){
if (typeof arguments[i] !== 'number') {
return undefined;
}
}
//store first argument into var 'num'
var num = arguments[0];
//if there is only 1 argument check if there is another
if (arguments.length === 1) {
return function(x){
for (var i = 0; i < arguments.length; i++){ //make sure its a number
if (typeof arguments[i] !== 'number') {
return undefined;
}
}
return x + num; //add the second given argument
};
} else {
return num + arguments[1]; //return if originally given 2 arguments
}
}
add(2)(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment