Created
July 26, 2022 22:08
-
-
Save IsraaMoqbel/75bdeb46999b013910866d2fa5f371a2 to your computer and use it in GitHub Desktop.
Calculate the factorial of a number. In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 5! = 5 x 4 x 3 x 2 x 1 = 120
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 === 1) { | |
| return 1; | |
| } | |
| return n * factorial(n - 1) | |
| } | |
| console.log(factorial(4)); // 24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment