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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user