Skip to content

Instantly share code, notes, and snippets.

@IsraaMoqbel
Created July 26, 2022 22:08
Show Gist options
  • Select an option

  • Save IsraaMoqbel/75bdeb46999b013910866d2fa5f371a2 to your computer and use it in GitHub Desktop.

Select an option

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
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