// Function to calculate the factorial of a number
function factorial(n) {
if (n === 0 || n === 1) {
return 1;
}
return n * factorial(n - 1);
}
// Example usage
const result = factorial(5);
console.log(result);
// Function to calculate the factorial of a number
function factorial(n) {
if (n === 0 || n === 1) {
return 1;
}
return n * factorial(n - 1);
}
// Example usage
const result = factorial(5);
console.log(result);
Related
How to implement a linked list using node js |
Write to function to calculate the factorial of a number |
How to implement a simple calculator using node js |
Find the Average of an Array using node js |
Write a function to capitalize the first letter of each word in a sentence using node js |
How to implement a Stack using node js |
Write a function to check if a number is prime using node js |
How to to check if a number is a palindrome using node js |