Last active
December 6, 2021 09:47
-
-
Save haase1020/77c103336efa107e3c8da276dd71672b to your computer and use it in GitHub Desktop.
factorial recursive
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
function factorial(n) { | |
if (n == 0 || n == 1) { | |
return 1; | |
} else { | |
console.log("running"); // should run 5 times | |
return n * factorial(n - 1); | |
} | |
} | |
console.log(factorial(5)); //5*4*3*2*1 = 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment