Factorial of Number Using Recursion
The factorial of a number is the product of all the numbers from 1 to that number.
- #Recursion
function fact(n) {
if (n < 0) throw new Error('Number must be positive');
if (n === 0) return 1;
return n * fact(n - 1);
}
console.log(fact(5));
Time Complexity O(n)/Space Complexity O(n)