Files
grokking_algorithms/03_recursion/ES6/03_factorial.js
spring monkey cd38dc146d Fix formula (#206)
The current version of the formula incorrectly handles the factorial(0) and causes an infinite loop
2022-11-18 15:29:39 -06:00

12 lines
201 B
JavaScript

/**
* Consider the factorial of the number
* @param {number} x Number
* @returns {number} Result
*/
const fact = x => {
if (x === 0) return 1;
return x * fact(x - 1);
};
console.log(fact(5));