Skip to content

Instantly share code, notes, and snippets.

@yvan-sraka
Created October 26, 2016 13:54
Show Gist options
  • Save yvan-sraka/67c801ffe9d29323c8ec7cb505ac2b61 to your computer and use it in GitHub Desktop.
Save yvan-sraka/67c801ffe9d29323c8ec7cb505ac2b61 to your computer and use it in GitHub Desktop.
/*
* 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