Factorial function
7 July 2024 (Updated 7 July 2024)
Here’s how to get the factorial of a number in JavaScript:
function factorial(num) {
if (num < 0) return -1
if (num === 0) return 1
return num * factorial(num - 1)
}
Tagged:
Algorithms
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment