Skip to content

Instantly share code, notes, and snippets.

@waseeld
Created May 25, 2021 14:46
Show Gist options
  • Save waseeld/dbc013eb990e6c457b7c16b8500c84d5 to your computer and use it in GitHub Desktop.
Save waseeld/dbc013eb990e6c457b7c16b8500c84d5 to your computer and use it in GitHub Desktop.
Create the function For get factorial
const factorial = (n) => {
if(n === 0){
return 1
}else{
return n * factorial(n-1)
}
}
const factorial_with_short_way = n => (n === 0 ? 1 : n * factorial(n - 1));
console.log(factorial(4)) // 24
console.log(factorial_with_short_way(4)) // 24
console.log(factorial(1)) // 1
console.log(factorial_with_short_way(0)) // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment