Last active
October 25, 2015 18:13
-
-
Save newswim/4a010b42902816b18f07 to your computer and use it in GitHub Desktop.
Free Code Camp JS Path *solutions
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
/* | |
Recursion | |
* | |
A function that evokes itself within its lexical scope | |
* | |
*/ | |
function factorialize(num) { | |
// If the number is less than 0, reject it. | |
if (num < 0) { | |
return -1; | |
} | |
// If the number is 0, its factorial is 1. | |
else if (num == 0) { | |
return 1; | |
} | |
// Otherwise, call this recursive procedure again. | |
else { | |
return (num * factorialize(num - 1)); | |
} | |
} | |
factorialize(5); // 120 | |
/* | |
Step 2 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment