Created
April 27, 2017 20:40
-
-
Save leonel-ai/d80fee2f5328668365eceb972ca094f7 to your computer and use it in GitHub Desktop.
freeCodeCamp Basic Algorithm Scripting: Challenge 02 - Recursion
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
// example of recursive algorithm | |
function factorialize(num) { | |
if (num < 0) { | |
return -1; // error msg | |
} | |
else if (num === 0) { | |
return 1; // base case | |
} | |
else { | |
return (num * factorialize(num - 1)); // general case | |
} | |
} | |
factorialize(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment