From ed7975aeb23bf8d48d9495905774177b521e28f9 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:34:29 +0000 Subject: [PATCH 01/18] feat| create spec files --- 13_factorial/factorial.spec.js | 40 +++++++++++++++++++ .../solution/factorial-solution.spec.js | 40 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 13_factorial/factorial.spec.js create mode 100644 13_factorial/solution/factorial-solution.spec.js diff --git a/13_factorial/factorial.spec.js b/13_factorial/factorial.spec.js new file mode 100644 index 00000000000..47be4957aa4 --- /dev/null +++ b/13_factorial/factorial.spec.js @@ -0,0 +1,40 @@ +const factorial = require("./factorial"); + +describe('factorial', () => { + test('4th factorial number is 24', () => { + expect(factorial(4)).toBe(24); + }); + test.skip('6th factorial number is 720', () => { + expect(factorial(6)).toBe(720); + }); + test.skip('10th factorial number is 3628800', () => { + expect(factorial(10)).toBe(3628800); + }); + test.skip('15th factorial number is 1.3076744e+12', () => { + expect(factorial(15)).toBe(1.3076744e12); + }); + test.skip('25th factorial number is 1.551121e+25', () => { + expect(factorial(25)).toBe(1.551121e25); + }); + test.skip('0th factorial number is 1', () => { + expect(factorial(0)).toBe(1); + }); + test.skip('doesn\'t accept negatives', () => { + expect(factorial(-25)).toBe(undefined); + }); + test.skip('doesn\'t accept floats', () => { + expect(factorial(5.4)).toBe(undefined); + }); + test.skip('DOES accept strings', () => { + expect(factorial("0")).toBe(1); + }); + test.skip('DOES accept strings', () => { + expect(factorial("1")).toBe(1); + }); + test.skip('DOES accept strings', () => { + expect(factorial("2")).toBe(2); + }); + test.skip('DOES accept strings', () => { + expect(factorial("8")).toBe(40320); + }); +}); diff --git a/13_factorial/solution/factorial-solution.spec.js b/13_factorial/solution/factorial-solution.spec.js new file mode 100644 index 00000000000..527dcccbc74 --- /dev/null +++ b/13_factorial/solution/factorial-solution.spec.js @@ -0,0 +1,40 @@ +const factorial = require("./factorial-solution"); + +describe('factorial', () => { + test('4th factorial number is 24', () => { + expect(factorial(4)).toBe(24); + }); + test.skip('6th factorial number is 720', () => { + expect(factorial(6)).toBe(720); + }); + test.skip('10th factorial number is 3628800', () => { + expect(factorial(10)).toBe(3628800); + }); + test.skip('15th factorial number is 1.3076744e+12', () => { + expect(factorial(15)).toBe(1.3076744e12); + }); + test.skip('25th factorial number is 1.551121e+25', () => { + expect(factorial(25)).toBe(1.551121e25); + }); + test.skip('0th factorial number is 1', () => { + expect(factorial(0)).toBe(1); + }); + test.skip('doesn\'t accept negatives', () => { + expect(factorial(-25)).toBe(undefined); + }); + test.skip('doesn\'t accept floats', () => { + expect(factorial(5.4)).toBe(undefined); + }); + test.skip('DOES accept strings', () => { + expect(factorial("0")).toBe(1); + }); + test.skip('DOES accept strings', () => { + expect(factorial("1")).toBe(1); + }); + test.skip('DOES accept strings', () => { + expect(factorial("2")).toBe(2); + }); + test.skip('DOES accept strings', () => { + expect(factorial("8")).toBe(40320); + }); +}); From 8845572e60eab5362e741fc405f55a9ef6ed4d30 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:35:25 +0000 Subject: [PATCH 02/18] feat| create readme --- 13_factorial/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 13_factorial/README.md diff --git a/13_factorial/README.md b/13_factorial/README.md new file mode 100644 index 00000000000..becd7d526da --- /dev/null +++ b/13_factorial/README.md @@ -0,0 +1,13 @@ +# Exercise 13 - Factorial + +Create a function that takes an input integer greater than or equal to 1 and returns the product of all its predecessing integers. If 0 is input it returns 1. It should accept strings that when converted to a number are valid inputs. For invalid inputs it returns `undefined`. + +For example: + +```javascript +factorial(2); // 2 * 1, Output: 2 +factorial('4'); // 4 * 3 * 2 * 1, Output: 24 +factorial(5); // 5 * 4 * 3 * 2 * 1, Output: 120 +factorial(7.2); // Output: undefined +factorial(0); // Output: 1 +``` From 670d85ea6a92ad26feb014e5a28e4b2658384560 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:36:50 +0000 Subject: [PATCH 03/18] feat| create solution files --- 13_factorial/factorial.js | 6 ++++++ 13_factorial/solution/factorial-solution.js | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 13_factorial/factorial.js create mode 100644 13_factorial/solution/factorial-solution.js diff --git a/13_factorial/factorial.js b/13_factorial/factorial.js new file mode 100644 index 00000000000..a88e4f6e573 --- /dev/null +++ b/13_factorial/factorial.js @@ -0,0 +1,6 @@ +const factorial = function() { + +}; + +// Do not edit below this line +module.exports = factorial; \ No newline at end of file diff --git a/13_factorial/solution/factorial-solution.js b/13_factorial/solution/factorial-solution.js new file mode 100644 index 00000000000..62dcaf2fc6b --- /dev/null +++ b/13_factorial/solution/factorial-solution.js @@ -0,0 +1,8 @@ +const factorial = function(n) { + if (/[.-]/.match(n + '')) return; + if (n === 0 || n === 1) return 1; + return factorial(n - 1) + factorial(n - 2); +}; + +// Do not edit below this line +module.exports = factorial; \ No newline at end of file From 4d4603191424613e8008c9c687a24d414ee41fa7 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:57:34 +0000 Subject: [PATCH 04/18] fix| factorial solution now passes --- 13_factorial/solution/factorial-solution.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/13_factorial/solution/factorial-solution.js b/13_factorial/solution/factorial-solution.js index 62dcaf2fc6b..d0f5e42a361 100644 --- a/13_factorial/solution/factorial-solution.js +++ b/13_factorial/solution/factorial-solution.js @@ -1,7 +1,7 @@ const factorial = function(n) { - if (/[.-]/.match(n + '')) return; - if (n === 0 || n === 1) return 1; - return factorial(n - 1) + factorial(n - 2); + if (/[-.]/.test(n + '')) return; + if (+n === 0 || +n === 1) return 1; + return n * factorial(n - 1); }; // Do not edit below this line From ee05ca925aa60a5472f4f15bd1c75e30ae428197 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:58:48 +0000 Subject: [PATCH 05/18] feat| spec file fixed --- .../solution/factorial-solution.spec.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/13_factorial/solution/factorial-solution.spec.js b/13_factorial/solution/factorial-solution.spec.js index 527dcccbc74..ec5ab50c31a 100644 --- a/13_factorial/solution/factorial-solution.spec.js +++ b/13_factorial/solution/factorial-solution.spec.js @@ -4,37 +4,37 @@ describe('factorial', () => { test('4th factorial number is 24', () => { expect(factorial(4)).toBe(24); }); - test.skip('6th factorial number is 720', () => { + test('6th factorial number is 720', () => { expect(factorial(6)).toBe(720); }); - test.skip('10th factorial number is 3628800', () => { + test('10th factorial number is 3628800', () => { expect(factorial(10)).toBe(3628800); }); - test.skip('15th factorial number is 1.3076744e+12', () => { - expect(factorial(15)).toBe(1.3076744e12); + test('15th factorial number is 1307674368000', () => { + expect(factorial(15)).toBe(1307674368000); }); - test.skip('25th factorial number is 1.551121e+25', () => { - expect(factorial(25)).toBe(1.551121e25); + test('25th factorial number is 1.5511210043330986e+255', () => { + expect(factorial(25)).toBe(1.5511210043330986e+25); }); - test.skip('0th factorial number is 1', () => { + test('0th factorial number is 1', () => { expect(factorial(0)).toBe(1); }); - test.skip('doesn\'t accept negatives', () => { + test('doesn\'t accept negatives', () => { expect(factorial(-25)).toBe(undefined); }); - test.skip('doesn\'t accept floats', () => { + test('doesn\'t accept floats', () => { expect(factorial(5.4)).toBe(undefined); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(factorial("0")).toBe(1); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(factorial("1")).toBe(1); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(factorial("2")).toBe(2); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(factorial("8")).toBe(40320); }); }); From f3174925119eac97115ff64b3ede1d3fbdc548e8 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:01:21 +0000 Subject: [PATCH 06/18] fix| spec --- 13_factorial/factorial.spec.js | 10 ++++----- .../solution/factorial-solution.spec.js | 22 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/13_factorial/factorial.spec.js b/13_factorial/factorial.spec.js index 47be4957aa4..95f97dd1eb5 100644 --- a/13_factorial/factorial.spec.js +++ b/13_factorial/factorial.spec.js @@ -1,4 +1,4 @@ -const factorial = require("./factorial"); +const factorial = require("./factorial-solution"); describe('factorial', () => { test('4th factorial number is 24', () => { @@ -10,11 +10,11 @@ describe('factorial', () => { test.skip('10th factorial number is 3628800', () => { expect(factorial(10)).toBe(3628800); }); - test.skip('15th factorial number is 1.3076744e+12', () => { - expect(factorial(15)).toBe(1.3076744e12); + test.skip('15th factorial number is 1307674368000', () => { + expect(factorial(15)).toBe(1307674368000); }); - test.skip('25th factorial number is 1.551121e+25', () => { - expect(factorial(25)).toBe(1.551121e25); + test.skip('25th factorial number is 1.5511210043330986e+255', () => { + expect(factorial(25)).toBe(1.5511210043330986e+25); }); test.skip('0th factorial number is 1', () => { expect(factorial(0)).toBe(1); diff --git a/13_factorial/solution/factorial-solution.spec.js b/13_factorial/solution/factorial-solution.spec.js index ec5ab50c31a..95f97dd1eb5 100644 --- a/13_factorial/solution/factorial-solution.spec.js +++ b/13_factorial/solution/factorial-solution.spec.js @@ -4,37 +4,37 @@ describe('factorial', () => { test('4th factorial number is 24', () => { expect(factorial(4)).toBe(24); }); - test('6th factorial number is 720', () => { + test.skip('6th factorial number is 720', () => { expect(factorial(6)).toBe(720); }); - test('10th factorial number is 3628800', () => { + test.skip('10th factorial number is 3628800', () => { expect(factorial(10)).toBe(3628800); }); - test('15th factorial number is 1307674368000', () => { + test.skip('15th factorial number is 1307674368000', () => { expect(factorial(15)).toBe(1307674368000); }); - test('25th factorial number is 1.5511210043330986e+255', () => { + test.skip('25th factorial number is 1.5511210043330986e+255', () => { expect(factorial(25)).toBe(1.5511210043330986e+25); }); - test('0th factorial number is 1', () => { + test.skip('0th factorial number is 1', () => { expect(factorial(0)).toBe(1); }); - test('doesn\'t accept negatives', () => { + test.skip('doesn\'t accept negatives', () => { expect(factorial(-25)).toBe(undefined); }); - test('doesn\'t accept floats', () => { + test.skip('doesn\'t accept floats', () => { expect(factorial(5.4)).toBe(undefined); }); - test('DOES accept strings', () => { + test.skip('DOES accept strings', () => { expect(factorial("0")).toBe(1); }); - test('DOES accept strings', () => { + test.skip('DOES accept strings', () => { expect(factorial("1")).toBe(1); }); - test('DOES accept strings', () => { + test.skip('DOES accept strings', () => { expect(factorial("2")).toBe(2); }); - test('DOES accept strings', () => { + test.skip('DOES accept strings', () => { expect(factorial("8")).toBe(40320); }); }); From 3530f26329f2bf61411902e539eda0dcb165c23e Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:25:10 +0000 Subject: [PATCH 07/18] feat/ add comments --- 13_factorial/factorial.spec.js | 2 +- 13_factorial/solution/factorial-solution.js | 6 ++++++ 13_factorial/solution/factorial-solution.spec.js | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/13_factorial/factorial.spec.js b/13_factorial/factorial.spec.js index 95f97dd1eb5..7794d091d6a 100644 --- a/13_factorial/factorial.spec.js +++ b/13_factorial/factorial.spec.js @@ -13,7 +13,7 @@ describe('factorial', () => { test.skip('15th factorial number is 1307674368000', () => { expect(factorial(15)).toBe(1307674368000); }); - test.skip('25th factorial number is 1.5511210043330986e+255', () => { + test.skip('25th factorial number is 1.5511210043330986e+25', () => { expect(factorial(25)).toBe(1.5511210043330986e+25); }); test.skip('0th factorial number is 1', () => { diff --git a/13_factorial/solution/factorial-solution.js b/13_factorial/solution/factorial-solution.js index d0f5e42a361..9cf4397b8b4 100644 --- a/13_factorial/solution/factorial-solution.js +++ b/13_factorial/solution/factorial-solution.js @@ -1,5 +1,11 @@ const factorial = function(n) { + // a negative number will always contain a '-' + // a non-integer will always contain a '.' + // the [-.] regex literal will match strings that contain a '-' or a '.' + // n + '' converts n to a string, which is required for the Regex.prototype.test method if (/[-.]/.test(n + '')) return; + + // +n converts n to a number if (+n === 0 || +n === 1) return 1; return n * factorial(n - 1); }; diff --git a/13_factorial/solution/factorial-solution.spec.js b/13_factorial/solution/factorial-solution.spec.js index 95f97dd1eb5..7794d091d6a 100644 --- a/13_factorial/solution/factorial-solution.spec.js +++ b/13_factorial/solution/factorial-solution.spec.js @@ -13,7 +13,7 @@ describe('factorial', () => { test.skip('15th factorial number is 1307674368000', () => { expect(factorial(15)).toBe(1307674368000); }); - test.skip('25th factorial number is 1.5511210043330986e+255', () => { + test.skip('25th factorial number is 1.5511210043330986e+25', () => { expect(factorial(25)).toBe(1.5511210043330986e+25); }); test.skip('0th factorial number is 1', () => { From 6c72df864b2db11c2ce49cf91742b6376fc03775 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:38:28 +0000 Subject: [PATCH 08/18] fix/ refactor --- 13_factorial/solution/factorial-solution.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/13_factorial/solution/factorial-solution.js b/13_factorial/solution/factorial-solution.js index 9cf4397b8b4..0478c3953fd 100644 --- a/13_factorial/solution/factorial-solution.js +++ b/13_factorial/solution/factorial-solution.js @@ -6,9 +6,9 @@ const factorial = function(n) { if (/[-.]/.test(n + '')) return; // +n converts n to a number - if (+n === 0 || +n === 1) return 1; + if (+n === 0) return 1; return n * factorial(n - 1); }; // Do not edit below this line -module.exports = factorial; \ No newline at end of file +module.exports = factorial; From dc40770f140edc528e734a73afa4b2c22c846516 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Sat, 23 Mar 2024 10:54:41 +0000 Subject: [PATCH 09/18] feat/ improve wording Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com> --- 13_factorial/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/13_factorial/README.md b/13_factorial/README.md index becd7d526da..8b4a077faaa 100644 --- a/13_factorial/README.md +++ b/13_factorial/README.md @@ -1,6 +1,6 @@ # Exercise 13 - Factorial -Create a function that takes an input integer greater than or equal to 1 and returns the product of all its predecessing integers. If 0 is input it returns 1. It should accept strings that when converted to a number are valid inputs. For invalid inputs it returns `undefined`. +Write a recursive function that takes a non-negative integer, and returns the product of all positive integers less than or equal to the input integer. An input of `0` should return `1`. The function should only accept numbers, so `'4'` should not be accepted as it is a string. All invalid inputs should return `undefined`. For example: From 882d418eb80203175acf08ded4571d61c17e95fa Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:04:16 +0000 Subject: [PATCH 10/18] feat/ update function to not accept strings --- 13_factorial/README.md | 3 +-- 13_factorial/factorial.spec.js | 13 ++----------- 13_factorial/solution/factorial-solution.js | 10 ++-------- 13_factorial/solution/factorial-solution.spec.js | 13 ++----------- 4 files changed, 7 insertions(+), 32 deletions(-) diff --git a/13_factorial/README.md b/13_factorial/README.md index 8b4a077faaa..b1f20df08eb 100644 --- a/13_factorial/README.md +++ b/13_factorial/README.md @@ -5,8 +5,7 @@ Write a recursive function that takes a non-negative integer, and returns the pr For example: ```javascript -factorial(2); // 2 * 1, Output: 2 -factorial('4'); // 4 * 3 * 2 * 1, Output: 24 +factorial('4'); // Output: undefined factorial(5); // 5 * 4 * 3 * 2 * 1, Output: 120 factorial(7.2); // Output: undefined factorial(0); // Output: 1 diff --git a/13_factorial/factorial.spec.js b/13_factorial/factorial.spec.js index 7794d091d6a..eddcb478ac9 100644 --- a/13_factorial/factorial.spec.js +++ b/13_factorial/factorial.spec.js @@ -25,16 +25,7 @@ describe('factorial', () => { test.skip('doesn\'t accept floats', () => { expect(factorial(5.4)).toBe(undefined); }); - test.skip('DOES accept strings', () => { - expect(factorial("0")).toBe(1); - }); - test.skip('DOES accept strings', () => { - expect(factorial("1")).toBe(1); - }); - test.skip('DOES accept strings', () => { - expect(factorial("2")).toBe(2); - }); - test.skip('DOES accept strings', () => { - expect(factorial("8")).toBe(40320); + test.skip('doesn\'t accept strings', () => { + expect(factorial('5')).toBe(undefined); }); }); diff --git a/13_factorial/solution/factorial-solution.js b/13_factorial/solution/factorial-solution.js index 0478c3953fd..2525458b88b 100644 --- a/13_factorial/solution/factorial-solution.js +++ b/13_factorial/solution/factorial-solution.js @@ -1,12 +1,6 @@ const factorial = function(n) { - // a negative number will always contain a '-' - // a non-integer will always contain a '.' - // the [-.] regex literal will match strings that contain a '-' or a '.' - // n + '' converts n to a string, which is required for the Regex.prototype.test method - if (/[-.]/.test(n + '')) return; - - // +n converts n to a number - if (+n === 0) return 1; + if (!Number.isInteger(n) || n < 0) return; + if (n === 0) return 1; return n * factorial(n - 1); }; diff --git a/13_factorial/solution/factorial-solution.spec.js b/13_factorial/solution/factorial-solution.spec.js index 7794d091d6a..eddcb478ac9 100644 --- a/13_factorial/solution/factorial-solution.spec.js +++ b/13_factorial/solution/factorial-solution.spec.js @@ -25,16 +25,7 @@ describe('factorial', () => { test.skip('doesn\'t accept floats', () => { expect(factorial(5.4)).toBe(undefined); }); - test.skip('DOES accept strings', () => { - expect(factorial("0")).toBe(1); - }); - test.skip('DOES accept strings', () => { - expect(factorial("1")).toBe(1); - }); - test.skip('DOES accept strings', () => { - expect(factorial("2")).toBe(2); - }); - test.skip('DOES accept strings', () => { - expect(factorial("8")).toBe(40320); + test.skip('doesn\'t accept strings', () => { + expect(factorial('5')).toBe(undefined); }); }); From 052637d71eb4937a90c49d7f9d1406966e726cc8 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:12:30 +0000 Subject: [PATCH 11/18] feat/ remove comment --- 13_factorial/solution/factorial-solution.js | 1 - 1 file changed, 1 deletion(-) diff --git a/13_factorial/solution/factorial-solution.js b/13_factorial/solution/factorial-solution.js index 2525458b88b..f28cc71b445 100644 --- a/13_factorial/solution/factorial-solution.js +++ b/13_factorial/solution/factorial-solution.js @@ -4,5 +4,4 @@ const factorial = function(n) { return n * factorial(n - 1); }; -// Do not edit below this line module.exports = factorial; From eaabc5ba1442c70af3bce3ed62b0eb0414343775 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Sat, 23 Mar 2024 13:11:17 +0000 Subject: [PATCH 12/18] feat/ improve order Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com> --- 13_factorial/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/13_factorial/README.md b/13_factorial/README.md index b1f20df08eb..847ba3fe8c5 100644 --- a/13_factorial/README.md +++ b/13_factorial/README.md @@ -5,8 +5,8 @@ Write a recursive function that takes a non-negative integer, and returns the pr For example: ```javascript -factorial('4'); // Output: undefined factorial(5); // 5 * 4 * 3 * 2 * 1, Output: 120 -factorial(7.2); // Output: undefined factorial(0); // Output: 1 +factorial(7.2); // Output: undefined +factorial('4'); // Output: undefined ``` From 3bc04827e37b09bb41a722a6617bb0b4d43c0f60 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Sat, 23 Mar 2024 14:30:53 +0000 Subject: [PATCH 13/18] feat/ remove unnecesary describe --- 13_factorial/factorial.spec.js | 8 +++++++- 13_factorial/solution/factorial-solution.spec.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/13_factorial/factorial.spec.js b/13_factorial/factorial.spec.js index eddcb478ac9..35c18e8b49c 100644 --- a/13_factorial/factorial.spec.js +++ b/13_factorial/factorial.spec.js @@ -25,7 +25,13 @@ describe('factorial', () => { test.skip('doesn\'t accept floats', () => { expect(factorial(5.4)).toBe(undefined); }); - test.skip('doesn\'t accept strings', () => { + test.skip('doesn\'t accept a number as a string', () => { expect(factorial('5')).toBe(undefined); }); + test.skip('doesn\'t accept strings', () => { + expect(factorial('foo')).toBe(undefined); + }); + test.skip('doesn\'t accept arrays', () => { + expect(factorial([5])).toBe(undefined); + }); }); diff --git a/13_factorial/solution/factorial-solution.spec.js b/13_factorial/solution/factorial-solution.spec.js index eddcb478ac9..35c18e8b49c 100644 --- a/13_factorial/solution/factorial-solution.spec.js +++ b/13_factorial/solution/factorial-solution.spec.js @@ -25,7 +25,13 @@ describe('factorial', () => { test.skip('doesn\'t accept floats', () => { expect(factorial(5.4)).toBe(undefined); }); - test.skip('doesn\'t accept strings', () => { + test.skip('doesn\'t accept a number as a string', () => { expect(factorial('5')).toBe(undefined); }); + test.skip('doesn\'t accept strings', () => { + expect(factorial('foo')).toBe(undefined); + }); + test.skip('doesn\'t accept arrays', () => { + expect(factorial([5])).toBe(undefined); + }); }); From ab1e7285deb7df3d86499ca26a3d166d3f9f8456 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:46:00 +0000 Subject: [PATCH 14/18] feat/ single quotes replaced with double quotes --- 13_factorial/factorial.spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/13_factorial/factorial.spec.js b/13_factorial/factorial.spec.js index 35c18e8b49c..a079053b572 100644 --- a/13_factorial/factorial.spec.js +++ b/13_factorial/factorial.spec.js @@ -19,19 +19,19 @@ describe('factorial', () => { test.skip('0th factorial number is 1', () => { expect(factorial(0)).toBe(1); }); - test.skip('doesn\'t accept negatives', () => { + test.skip("doesn't accept negatives", () => { expect(factorial(-25)).toBe(undefined); }); - test.skip('doesn\'t accept floats', () => { + test.skip("doesn't accept floats", () => { expect(factorial(5.4)).toBe(undefined); }); - test.skip('doesn\'t accept a number as a string', () => { + test.skip("doesn't accept a number as a string", () => { expect(factorial('5')).toBe(undefined); }); - test.skip('doesn\'t accept strings', () => { + test.skip("doesn't accept strings", () => { expect(factorial('foo')).toBe(undefined); }); - test.skip('doesn\'t accept arrays', () => { + test.skip("doesn't accept arrays", () => { expect(factorial([5])).toBe(undefined); }); }); From f1f29ac500be711682bb8a16fd04b5d3dc5b53b5 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:48:50 +0000 Subject: [PATCH 15/18] feat/ add wikipedia link to factorial --- 13_factorial/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/13_factorial/README.md b/13_factorial/README.md index 847ba3fe8c5..17831cbd7b3 100644 --- a/13_factorial/README.md +++ b/13_factorial/README.md @@ -1,6 +1,6 @@ # Exercise 13 - Factorial -Write a recursive function that takes a non-negative integer, and returns the product of all positive integers less than or equal to the input integer. An input of `0` should return `1`. The function should only accept numbers, so `'4'` should not be accepted as it is a string. All invalid inputs should return `undefined`. +Write a [recursive factorial function](https://simple.wikipedia.org/wiki/Factorial) that takes a non-negative integer, and returns the product of all positive integers less than or equal to the input integer. An input of `0` should return `1`. The function should only accept numbers, so `'4'` should not be accepted as it is a string. All invalid inputs should return `undefined`. For example: From 54dd2ce3f9cc7337a671a65cfc57b1fa7326d283 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Sat, 23 Mar 2024 19:13:16 +0000 Subject: [PATCH 16/18] Update 13_factorial/README.md Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com> --- 13_factorial/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/13_factorial/README.md b/13_factorial/README.md index 17831cbd7b3..ecd8388fa6a 100644 --- a/13_factorial/README.md +++ b/13_factorial/README.md @@ -1,6 +1,6 @@ # Exercise 13 - Factorial -Write a [recursive factorial function](https://simple.wikipedia.org/wiki/Factorial) that takes a non-negative integer, and returns the product of all positive integers less than or equal to the input integer. An input of `0` should return `1`. The function should only accept numbers, so `'4'` should not be accepted as it is a string. All invalid inputs should return `undefined`. +Write a recursive [factorial](https://simple.wikipedia.org/wiki/Factorial) function that takes a non-negative integer, and returns the product of all positive integers less than or equal to the input integer. An input of `0` should return `1`. The function should only accept numbers, so `'4'` should not be accepted as it is a string. All invalid inputs should return `undefined`. For example: From 8b2ed42f9a8547dbea98420d5892dbac02ef0231 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Sun, 24 Mar 2024 11:20:14 +0000 Subject: [PATCH 17/18] Update 13_factorial/factorial.spec.js Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com> --- 13_factorial/factorial.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/13_factorial/factorial.spec.js b/13_factorial/factorial.spec.js index a079053b572..4250d5d9500 100644 --- a/13_factorial/factorial.spec.js +++ b/13_factorial/factorial.spec.js @@ -1,4 +1,4 @@ -const factorial = require("./factorial-solution"); +const factorial = require("./factorial"); describe('factorial', () => { test('4th factorial number is 24', () => { From 10d559dc5dfad55399fedd36050bc68053ee923d Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Tue, 20 Aug 2024 23:28:08 +0100 Subject: [PATCH 18/18] feat(factorial): remove .skip from all tests under solution --- .../solution/factorial-solution.spec.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/13_factorial/solution/factorial-solution.spec.js b/13_factorial/solution/factorial-solution.spec.js index 35c18e8b49c..7532f54c990 100644 --- a/13_factorial/solution/factorial-solution.spec.js +++ b/13_factorial/solution/factorial-solution.spec.js @@ -4,34 +4,34 @@ describe('factorial', () => { test('4th factorial number is 24', () => { expect(factorial(4)).toBe(24); }); - test.skip('6th factorial number is 720', () => { + test('6th factorial number is 720', () => { expect(factorial(6)).toBe(720); }); - test.skip('10th factorial number is 3628800', () => { + test('10th factorial number is 3628800', () => { expect(factorial(10)).toBe(3628800); }); - test.skip('15th factorial number is 1307674368000', () => { + test('15th factorial number is 1307674368000', () => { expect(factorial(15)).toBe(1307674368000); }); - test.skip('25th factorial number is 1.5511210043330986e+25', () => { + test('25th factorial number is 1.5511210043330986e+25', () => { expect(factorial(25)).toBe(1.5511210043330986e+25); }); - test.skip('0th factorial number is 1', () => { + test('0th factorial number is 1', () => { expect(factorial(0)).toBe(1); }); - test.skip('doesn\'t accept negatives', () => { + test('doesn\'t accept negatives', () => { expect(factorial(-25)).toBe(undefined); }); - test.skip('doesn\'t accept floats', () => { + test('doesn\'t accept floats', () => { expect(factorial(5.4)).toBe(undefined); }); - test.skip('doesn\'t accept a number as a string', () => { + test('doesn\'t accept a number as a string', () => { expect(factorial('5')).toBe(undefined); }); - test.skip('doesn\'t accept strings', () => { + test('doesn\'t accept strings', () => { expect(factorial('foo')).toBe(undefined); }); - test.skip('doesn\'t accept arrays', () => { + test('doesn\'t accept arrays', () => { expect(factorial([5])).toBe(undefined); }); });