Skip to content

Instantly share code, notes, and snippets.

@bogoreh
Created March 2, 2021 11:50
Show Gist options
  • Select an option

  • Save bogoreh/6c77b8015495d41a91010237763517b0 to your computer and use it in GitHub Desktop.

Select an option

Save bogoreh/6c77b8015495d41a91010237763517b0 to your computer and use it in GitHub Desktop.
var factorial = function(n) {
// base case:
if (n === 0){
return 1;
}
// recursive case:
return n* factorial(n-1);
};
println("The value of 0! is " + factorial(0) + ".");
println("The value of 5! is " + factorial(5) + ".");
Program.assertEqual(factorial(0), 1);
Program.assertEqual(factorial(5), 120);
Program.assertEqual(factorial(7), 5040);
Program.assertEqual(factorial(3), 6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment