Created
October 26, 2016 13:54
-
-
Save yvan-sraka/67c801ffe9d29323c8ec7cb505ac2b61 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* Factorial | |
* n! = 1 * 2 * .. * n | |
* | |
* 5! = 5 * 4 * 3 * 2 * 1 = 120 | |
*/ | |
// MATHS: | |
// 0! = 1 | |
// n! = n * (n - 1)! | |
function fac(n) { | |
if (n <= 1) { | |
return 1; | |
} else { | |
return n * fac(n - 1); | |
} | |
} | |
/* TEST */ | |
fac(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment