Created
May 25, 2021 14:46
-
-
Save waseeld/dbc013eb990e6c457b7c16b8500c84d5 to your computer and use it in GitHub Desktop.
Create the function For get factorial
This file contains 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
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