Skip to content

Instantly share code, notes, and snippets.

@newswim
Last active October 25, 2015 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newswim/4a010b42902816b18f07 to your computer and use it in GitHub Desktop.
Save newswim/4a010b42902816b18f07 to your computer and use it in GitHub Desktop.
Free Code Camp JS Path *solutions
/*
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