console.log("Find Factorial of a give number using Javascript: ");
//iterative approach
const findFactorial = (number) => {
if(number === 1 || number === 0)
return 1;
let total = 1;
for ( let i = number; i >= 1; i--) {
total = total*i;
}
return total;
}
console.log(findFactorial(6)); //720
//recursive approach
const findRecursiveFactorial = (number) => {
if (number === 0 || number === 1 )
return 1;
else
return number * findRecursiveFactorial(number - 1);
}
console.log(findRecursiveFactorial(6)); //720