Created
August 9, 2015 18:22
-
-
Save svahora/d1ced732c9cf57fb79b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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