// 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 |
How to implement a simple calculator using node js |
How to convert Celsius to Fahrenheit using node js |
How to check if two strings are anagrams |
Write program to remove duplicates from an Array |
How to implement a Queue |
Write a program to find Reverse a String using node js |
Write to function to calculate the factorial of a number |