Skip to content

Instantly share code, notes, and snippets.

@haase1020
Last active December 6, 2021 09:47
Show Gist options
  • Save haase1020/77c103336efa107e3c8da276dd71672b to your computer and use it in GitHub Desktop.
Save haase1020/77c103336efa107e3c8da276dd71672b to your computer and use it in GitHub Desktop.
factorial recursive
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