Last active
December 10, 2018 21:46
-
-
Save Angelfire/6a749edebb5850500a07de4c9baedc82 to your computer and use it in GitHub Desktop.
Factorial
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
/** | |
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