Skip to content

Commit 3530f26

Browse files
committed
feat/ add comments
1 parent f317492 commit 3530f26

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

13_factorial/factorial.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('factorial', () => {
1313
test.skip('15th factorial number is 1307674368000', () => {
1414
expect(factorial(15)).toBe(1307674368000);
1515
});
16-
test.skip('25th factorial number is 1.5511210043330986e+255', () => {
16+
test.skip('25th factorial number is 1.5511210043330986e+25', () => {
1717
expect(factorial(25)).toBe(1.5511210043330986e+25);
1818
});
1919
test.skip('0th factorial number is 1', () => {

13_factorial/solution/factorial-solution.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
const factorial = function(n) {
2+
// a negative number will always contain a '-'
3+
// a non-integer will always contain a '.'
4+
// the [-.] regex literal will match strings that contain a '-' or a '.'
5+
// n + '' converts n to a string, which is required for the Regex.prototype.test method
26
if (/[-.]/.test(n + '')) return;
7+
8+
// +n converts n to a number
39
if (+n === 0 || +n === 1) return 1;
410
return n * factorial(n - 1);
511
};

13_factorial/solution/factorial-solution.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('factorial', () => {
1313
test.skip('15th factorial number is 1307674368000', () => {
1414
expect(factorial(15)).toBe(1307674368000);
1515
});
16-
test.skip('25th factorial number is 1.5511210043330986e+255', () => {
16+
test.skip('25th factorial number is 1.5511210043330986e+25', () => {
1717
expect(factorial(25)).toBe(1.5511210043330986e+25);
1818
});
1919
test.skip('0th factorial number is 1', () => {

0 commit comments

Comments
 (0)