The current version of the formula incorrectly handles the factorial(0) and causes an infinite loop
12 lines
201 B
JavaScript
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));
|