Created
March 2, 2021 11:50
-
-
Save bogoreh/6c77b8015495d41a91010237763517b0 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
| 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