Created
December 4, 2015 21:13
-
-
Save clive-bunting/ef83b1cf2373b934bfb6 to your computer and use it in GitHub Desktop.
Bonfire: Arguments Optional
This file contains hidden or 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
| // Bonfire: Arguments Optional | |
| // Author: @clive-bunting | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-arguments-optional | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function add() { | |
| if (typeof arguments[0] !== "number") { | |
| return undefined; | |
| } | |
| var first = arguments[0]; | |
| if (arguments[1] === undefined) { | |
| return function() { | |
| if (typeof arguments[0] !== "number") { | |
| return undefined; | |
| } | |
| return first + arguments[0]; | |
| }; | |
| } | |
| if (typeof arguments[1] !== "number") { | |
| return undefined; | |
| } | |
| return first + arguments[1]; | |
| } | |
| add(2,3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment