We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 670d85e commit 4d46031Copy full SHA for 4d46031
13_factorial/solution/factorial-solution.js
@@ -1,7 +1,7 @@
1
const factorial = function(n) {
2
- if (/[.-]/.match(n + '')) return;
3
- if (n === 0 || n === 1) return 1;
4
- return factorial(n - 1) + factorial(n - 2);
+ if (/[-.]/.test(n + '')) return;
+ if (+n === 0 || +n === 1) return 1;
+ return n * factorial(n - 1);
5
};
6
7
// Do not edit below this line
0 commit comments