factorial formula adjustement

The formula in book is incorrect because it doesn't include the factorial(0) case and leads to infinite recursion in this case.
This commit is contained in:
Yulia Kolupaeva
2021-02-16 18:10:25 +03:00
parent f1acf84f3a
commit 0c4fdddb12

View File

@@ -4,7 +4,7 @@
* @returns {number} Result
*/
function fact(x) {
if (x === 1) return 1;
if (x === 0) return 1;
return x * fact(x - 1);
}