Skip to content

Instantly share code, notes, and snippets.

@Angelfire
Last active December 10, 2018 21:46
Show Gist options
  • Save Angelfire/6a749edebb5850500a07de4c9baedc82 to your computer and use it in GitHub Desktop.
Save Angelfire/6a749edebb5850500a07de4c9baedc82 to your computer and use it in GitHub Desktop.
Factorial
/**
Challenge
Factorial
Sample Test Cases
Input: 1
Output: 1
Input: 4
Output: 24
Input: 9
Output: 362880
*/
function FirstFactorial(num) {
if (num === 0) {
return 1;
} else {
return num * FirstFactorial(num - 1);
}
}
// ES6
firstFactorial = num => {
return num === 0 ? 1 : num * firstFactorial(num -1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment