From f2c0d0955b83a56e4ebb737765b09ca129407185 Mon Sep 17 00:00:00 2001 From: Miko <100534556+jamienorthman@users.noreply.github.com> Date: Mon, 18 Sep 2023 23:01:33 +0200 Subject: [PATCH 1/8] Added handling of string case for 0 --- 10_fibonacci/solution/fibonacci-solution.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/10_fibonacci/solution/fibonacci-solution.js b/10_fibonacci/solution/fibonacci-solution.js index acdd1e0..a002ffe 100644 --- a/10_fibonacci/solution/fibonacci-solution.js +++ b/10_fibonacci/solution/fibonacci-solution.js @@ -1,6 +1,6 @@ const fibonacci = function(count) { if (count < 0) return "OOPS"; - if (count === 0) return 0; + if (count == 0) return 0; let firstPrev = 1; let secondPrev = 0; From 5ac1931f72c1b04ff1bd30ddc653280e43d130e6 Mon Sep 17 00:00:00 2001 From: Miko <100534556+jamienorthman@users.noreply.github.com> Date: Mon, 18 Sep 2023 23:06:29 +0200 Subject: [PATCH 2/8] Added test cases for 0 and string 0 --- 10_fibonacci/fibonacci.spec.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/10_fibonacci/fibonacci.spec.js b/10_fibonacci/fibonacci.spec.js index 7f62213..7617791 100644 --- a/10_fibonacci/fibonacci.spec.js +++ b/10_fibonacci/fibonacci.spec.js @@ -16,9 +16,15 @@ describe('fibonacci', () => { test.skip('25th fibonacci number is 75025', () => { expect(fibonacci(25)).toBe(75025); }); + test('0th fibonacci number is o', () => { + expect(fibonacci(0)).toBe(0); + }); test.skip('doesn\'t accept negatives', () => { expect(fibonacci(-25)).toBe("OOPS"); }); + test.skip('DOES accept strings', () => { + expect(fibonacci("0")).toBe(0); + }); test.skip('DOES accept strings', () => { expect(fibonacci("1")).toBe(1); }); From 59a2f1ce4796c905f3e680c66ffbfcc04de20e46 Mon Sep 17 00:00:00 2001 From: Miko <100534556+jamienorthman@users.noreply.github.com> Date: Mon, 18 Sep 2023 23:06:51 +0200 Subject: [PATCH 3/8] Added test case for string 0 --- .../solution/fibonacci-solution.spec.js | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/10_fibonacci/solution/fibonacci-solution.spec.js b/10_fibonacci/solution/fibonacci-solution.spec.js index 4e6a44d..7617791 100644 --- a/10_fibonacci/solution/fibonacci-solution.spec.js +++ b/10_fibonacci/solution/fibonacci-solution.spec.js @@ -1,34 +1,37 @@ -const fibonacci = require('./fibonacci-solution'); +const fibonacci = require('./fibonacci') describe('fibonacci', () => { test('4th fibonacci number is 3', () => { expect(fibonacci(4)).toBe(3); }); - test('6th fibonacci number is 8', () => { + test.skip('6th fibonacci number is 8', () => { expect(fibonacci(6)).toBe(8); }); - test('10th fibonacci number is 55', () => { + test.skip('10th fibonacci number is 55', () => { expect(fibonacci(10)).toBe(55); }); - test('15th fibonacci number is 610', () => { + test.skip('15th fibonacci number is 610', () => { expect(fibonacci(15)).toBe(610); }); - test('25th fibonacci number is 75025', () => { + test.skip('25th fibonacci number is 75025', () => { expect(fibonacci(25)).toBe(75025); }); test('0th fibonacci number is o', () => { expect(fibonacci(0)).toBe(0); }); - test("doesn't accept negatives", () => { - expect(fibonacci(-25)).toBe('OOPS'); + test.skip('doesn\'t accept negatives', () => { + expect(fibonacci(-25)).toBe("OOPS"); }); - test('DOES accept strings', () => { - expect(fibonacci('1')).toBe(1); + test.skip('DOES accept strings', () => { + expect(fibonacci("0")).toBe(0); }); - test('DOES accept strings', () => { - expect(fibonacci('2')).toBe(1); + test.skip('DOES accept strings', () => { + expect(fibonacci("1")).toBe(1); }); - test('DOES accept strings', () => { - expect(fibonacci('8')).toBe(21); + test.skip('DOES accept strings', () => { + expect(fibonacci("2")).toBe(1); + }); + test.skip('DOES accept strings', () => { + expect(fibonacci("8")).toBe(21); }); }); From 3b84151724a57466fd88b752dee7514ead739644 Mon Sep 17 00:00:00 2001 From: Miko <100534556+jamienorthman@users.noreply.github.com> Date: Mon, 18 Sep 2023 23:11:09 +0200 Subject: [PATCH 4/8] Fixed usage of test (no skip) in solution --- .../solution/fibonacci-solution.spec.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/10_fibonacci/solution/fibonacci-solution.spec.js b/10_fibonacci/solution/fibonacci-solution.spec.js index 7617791..3bbaa61 100644 --- a/10_fibonacci/solution/fibonacci-solution.spec.js +++ b/10_fibonacci/solution/fibonacci-solution.spec.js @@ -1,37 +1,37 @@ -const fibonacci = require('./fibonacci') +const fibonacci = require('./fibonacci-solution') describe('fibonacci', () => { test('4th fibonacci number is 3', () => { expect(fibonacci(4)).toBe(3); }); - test.skip('6th fibonacci number is 8', () => { + test('6th fibonacci number is 8', () => { expect(fibonacci(6)).toBe(8); }); - test.skip('10th fibonacci number is 55', () => { + test('10th fibonacci number is 55', () => { expect(fibonacci(10)).toBe(55); }); - test.skip('15th fibonacci number is 610', () => { + test('15th fibonacci number is 610', () => { expect(fibonacci(15)).toBe(610); }); - test.skip('25th fibonacci number is 75025', () => { + test('25th fibonacci number is 75025', () => { expect(fibonacci(25)).toBe(75025); }); test('0th fibonacci number is o', () => { expect(fibonacci(0)).toBe(0); }); - test.skip('doesn\'t accept negatives', () => { + test('doesn\'t accept negatives', () => { expect(fibonacci(-25)).toBe("OOPS"); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(fibonacci("0")).toBe(0); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(fibonacci("1")).toBe(1); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(fibonacci("2")).toBe(1); }); - test.skip('DOES accept strings', () => { + test('DOES accept strings', () => { expect(fibonacci("8")).toBe(21); }); }); From e5c0f77d21b72996fd1535a1aa7fa5b7ce1ecd3f Mon Sep 17 00:00:00 2001 From: Miko <100534556+jamienorthman@users.noreply.github.com> Date: Mon, 18 Sep 2023 23:11:41 +0200 Subject: [PATCH 5/8] Fixed usage of test (skip all but first) in exercise --- 10_fibonacci/fibonacci.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/10_fibonacci/fibonacci.spec.js b/10_fibonacci/fibonacci.spec.js index 7617791..6bf1fd9 100644 --- a/10_fibonacci/fibonacci.spec.js +++ b/10_fibonacci/fibonacci.spec.js @@ -16,7 +16,7 @@ describe('fibonacci', () => { test.skip('25th fibonacci number is 75025', () => { expect(fibonacci(25)).toBe(75025); }); - test('0th fibonacci number is o', () => { + test.skip('0th fibonacci number is o', () => { expect(fibonacci(0)).toBe(0); }); test.skip('doesn\'t accept negatives', () => { From 38f0da96437874b26ad223c9ebc75b59a780ed18 Mon Sep 17 00:00:00 2001 From: Miko <100534556+jamienorthman@users.noreply.github.com> Date: Sun, 29 Oct 2023 11:51:42 +0100 Subject: [PATCH 6/8] More consistent spelling in 10_fibonacci Co-authored-by: Alex Younger <61510135+fortypercenttitanium@users.noreply.github.com> --- 10_fibonacci/solution/fibonacci-solution.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/10_fibonacci/solution/fibonacci-solution.spec.js b/10_fibonacci/solution/fibonacci-solution.spec.js index 3bbaa61..33023e8 100644 --- a/10_fibonacci/solution/fibonacci-solution.spec.js +++ b/10_fibonacci/solution/fibonacci-solution.spec.js @@ -16,7 +16,7 @@ describe('fibonacci', () => { test('25th fibonacci number is 75025', () => { expect(fibonacci(25)).toBe(75025); }); - test('0th fibonacci number is o', () => { + test('0th fibonacci number is 0', () => { expect(fibonacci(0)).toBe(0); }); test('doesn\'t accept negatives', () => { From 4a03e410bf7fb4fdd23d2f3180f58fbd006bafe8 Mon Sep 17 00:00:00 2001 From: Miko <100534556+jamienorthman@users.noreply.github.com> Date: Sun, 29 Oct 2023 11:52:01 +0100 Subject: [PATCH 7/8] More consistent spelling in 10_fibonacci Co-authored-by: Alex Younger <61510135+fortypercenttitanium@users.noreply.github.com> --- 10_fibonacci/fibonacci.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/10_fibonacci/fibonacci.spec.js b/10_fibonacci/fibonacci.spec.js index 6bf1fd9..de632d8 100644 --- a/10_fibonacci/fibonacci.spec.js +++ b/10_fibonacci/fibonacci.spec.js @@ -16,7 +16,7 @@ describe('fibonacci', () => { test.skip('25th fibonacci number is 75025', () => { expect(fibonacci(25)).toBe(75025); }); - test.skip('0th fibonacci number is o', () => { + test.skip('0th fibonacci number is 0', () => { expect(fibonacci(0)).toBe(0); }); test.skip('doesn\'t accept negatives', () => { From 80ca665767a48a52f2a7c57510f384b89eec3b43 Mon Sep 17 00:00:00 2001 From: Jamienorthman Date: Sun, 29 Oct 2023 12:36:58 +0100 Subject: [PATCH 8/8] added explicit conversion to number for fibonacci solution --- 10_fibonacci/solution/fibonacci-solution.js | 13 +++++++++++-- 10_fibonacci/solution/fibonacci-solution.spec.js | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/10_fibonacci/solution/fibonacci-solution.js b/10_fibonacci/solution/fibonacci-solution.js index a002ffe..953a5e1 100644 --- a/10_fibonacci/solution/fibonacci-solution.js +++ b/10_fibonacci/solution/fibonacci-solution.js @@ -1,4 +1,13 @@ -const fibonacci = function(count) { +const fibonacci = function(countArg) { + // checks argument's type and makes sure we use + // a number throughout rest of function. + let count + if (typeof countArg !== 'number') { + count = parseInt(countArg) + } else { + count = countArg + } + if (count < 0) return "OOPS"; if (count == 0) return 0; @@ -14,4 +23,4 @@ const fibonacci = function(count) { return firstPrev; }; -module.exports = fibonacci; +module.exports = fibonacci; \ No newline at end of file diff --git a/10_fibonacci/solution/fibonacci-solution.spec.js b/10_fibonacci/solution/fibonacci-solution.spec.js index 33023e8..fdb0bad 100644 --- a/10_fibonacci/solution/fibonacci-solution.spec.js +++ b/10_fibonacci/solution/fibonacci-solution.spec.js @@ -34,4 +34,4 @@ describe('fibonacci', () => { test('DOES accept strings', () => { expect(fibonacci("8")).toBe(21); }); -}); +}); \ No newline at end of file