Skip to content

Instantly share code, notes, and snippets.

@leonel-ai
Created April 27, 2017 20:40
Show Gist options
  • Save leonel-ai/d80fee2f5328668365eceb972ca094f7 to your computer and use it in GitHub Desktop.
Save leonel-ai/d80fee2f5328668365eceb972ca094f7 to your computer and use it in GitHub Desktop.
freeCodeCamp Basic Algorithm Scripting: Challenge 02 - Recursion
// 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