From 09fe065676e4a5ec1d83c5a11d10c6e73431301e Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 00:51:45 +0100 Subject: [PATCH 01/55] Fix median calculation to return correct value from the list --- Sprint-1/fix/median.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 5c5b796e1..f1c9fa535 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -7,7 +7,7 @@ function calculateMedian(list) { const middleIndex = Math.floor(list.length / 2); - const median = list.splice(middleIndex, 1)[0]; + const median = list[middleIndex]; return median; } From 1fde0e09290f5e354f5f29e93cfc058aea2a1b98 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 00:54:14 +0100 Subject: [PATCH 02/55] Fix median calculation to handle both odd and even length lists --- Sprint-1/fix/median.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index f1c9fa535..1a5c79899 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -7,8 +7,13 @@ function calculateMedian(list) { const middleIndex = Math.floor(list.length / 2); - const median = list[middleIndex]; - return median; + if (list.length % 2 === 1) { + return list[middleIndex]; + } + + const lowerMiddle = list[middleIndex - 1]; + const upperMiddle = list[middleIndex]; + return (lowerMiddle + upperMiddle) / 2; } module.exports = calculateMedian; From ecfa4aa750bb66cbf6c700d5509409dcff9309ae Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 00:57:20 +0100 Subject: [PATCH 03/55] Fix median calculation to use sorted list --- Sprint-1/fix/median.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 1a5c79899..1400c1783 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,13 +6,14 @@ // or contains values that aren't numbers (the function is expected to throw - see the tests). function calculateMedian(list) { + const sortedList = [...list].sort((a, b) => a - b); const middleIndex = Math.floor(list.length / 2); if (list.length % 2 === 1) { - return list[middleIndex]; + return sortedList[middleIndex]; } - const lowerMiddle = list[middleIndex - 1]; - const upperMiddle = list[middleIndex]; + const lowerMiddle = sortedList[middleIndex - 1]; + const upperMiddle = sortedList[middleIndex]; return (lowerMiddle + upperMiddle) / 2; } From fd8ec6688bc351946e7013229fdb8c402023de27 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 00:59:29 +0100 Subject: [PATCH 04/55] Add error handling for input validation to calculateMedian function --- Sprint-1/fix/median.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 1400c1783..67c85db69 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,6 +6,10 @@ // or contains values that aren't numbers (the function is expected to throw - see the tests). function calculateMedian(list) { + + if (!Array.isArray(list)) { + throw new Error("calculateMedian requires an array of numbers"); + } const sortedList = [...list].sort((a, b) => a - b); const middleIndex = Math.floor(list.length / 2); if (list.length % 2 === 1) { From e3e6ea53c254b8d50428184d3ed4a05cded7faab Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 01:01:57 +0100 Subject: [PATCH 05/55] Add error handling for empty array --- Sprint-1/fix/median.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 67c85db69..d0a228bb5 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -10,6 +10,11 @@ function calculateMedian(list) { if (!Array.isArray(list)) { throw new Error("calculateMedian requires an array of numbers"); } + + if (list.length === 0) { + throw new Error("calculateMedian requires a non-empty array"); + } + const sortedList = [...list].sort((a, b) => a - b); const middleIndex = Math.floor(list.length / 2); if (list.length % 2 === 1) { From e95631ca340099e59ba79d16718abb66ea86aaf2 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 01:04:05 +0100 Subject: [PATCH 06/55] Add error handling to ensure all elements in the array are numbers --- Sprint-1/fix/median.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index d0a228bb5..0b327cb54 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -15,6 +15,12 @@ function calculateMedian(list) { throw new Error("calculateMedian requires a non-empty array"); } + for (const item of list) { + if (typeof item !== "number") { + throw new Error("calculateMedian requires an array of numbers"); + } + } + const sortedList = [...list].sort((a, b) => a - b); const middleIndex = Math.floor(list.length / 2); if (list.length % 2 === 1) { From bba68b6978cffefde91474fb5e778c581904e553 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:00:34 +0100 Subject: [PATCH 07/55] Implement test for empty array case in findMax function --- Sprint-1/implement/max.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index ff3fbb5e5..920fb8ec3 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -16,7 +16,9 @@ const findMax = require("./max.js"); // When passed to the max function // Then it should return -Infinity // Delete this test.todo and replace it with a test. -test.todo("given an empty array, returns -Infinity"); +test("given an empty array, returns -Infinity", ()=> { + expect(findMax([])).toBe(-Infinity); +}); // Given an array with one number // When passed to the max function From 66a3e6add8d0b2a03208ad242cd8fca47e933f1f Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:04:07 +0100 Subject: [PATCH 08/55] Add input validation to findMax function to ensure an array is provided --- Sprint-1/implement/max.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..ecd78095a 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,7 @@ function findMax(elements) { + if(!Array.isArray(elements)) { + throw new Error("findMax requires an array of numbers"); + } } module.exports = findMax; From ed01080f3b20b34bb345f114942d1337d398d642 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:09:16 +0100 Subject: [PATCH 09/55] Refactor findMax function to include max initialization --- Sprint-1/implement/max.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index ecd78095a..80671e96f 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -2,6 +2,14 @@ function findMax(elements) { if(!Array.isArray(elements)) { throw new Error("findMax requires an array of numbers"); } + + let max = -Infinity; + + for (const element of elements) { + if (typeof element !== "number" || Number.isNaN(element)) { + throw new Error("findMax requires an array of numbers"); + } + } } module.exports = findMax; From b564d44b10090e15db0525043ede5544ae2d80a8 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:12:36 +0100 Subject: [PATCH 10/55] Add test for single number array case in findMax function --- Sprint-1/implement/max.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 920fb8ec3..b2759028d 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -23,6 +23,9 @@ test("given an empty array, returns -Infinity", ()=> { // Given an array with one number // When passed to the max function // Then it should return that number +test("given an array with one number, returns that number", () => { + expect(findMax([7])).toBe(7); +}); // Given an array with both positive and negative numbers // When passed to the max function From f104afb84de3da0466b8625caad1a8bc107d9048 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:13:48 +0100 Subject: [PATCH 11/55] Refactor findMax function --- Sprint-1/implement/max.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 80671e96f..e991aea97 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -9,7 +9,12 @@ function findMax(elements) { if (typeof element !== "number" || Number.isNaN(element)) { throw new Error("findMax requires an array of numbers"); } + + if (element > max) { + max = element; + } } + return max; } module.exports = findMax; From b6f529d26dbb5e325f809d604cf63d08b3e7808e Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:16:48 +0100 Subject: [PATCH 12/55] Add test for non-number input in findMax function --- Sprint-1/implement/max.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index b2759028d..f58225542 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -42,6 +42,9 @@ test("given an array with one number, returns that number", () => { // Given an array containing a value that isn't a number // When passed to the max function // Then it should throw Error("findMax requires an array of numbers") +test("given an array with a non-number, throws an error", () => { + expect(() => findMax(["hey", 10, "hi", 60, 10])).toThrow("findMax requires an array of numbers"); +}); // Given something that isn't an array at all, such as "hey", 42 or no argument // When passed to the max function From c7b0e6e9dacbae0a48f4bb7173bcdd70ac72ffce Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:20:53 +0100 Subject: [PATCH 13/55] Add test for non-array inputs in findMax function --- Sprint-1/implement/max.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index f58225542..f92bcc7ff 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -49,3 +49,8 @@ test("given an array with a non-number, throws an error", () => { // Given something that isn't an array at all, such as "hey", 42 or no argument // When passed to the max function // Then it should throw Error("findMax requires an array of numbers") +test("given something that is not an array, throws an error", () => { + expect(() => findMax("hey")).toThrow("findMax requires an array of numbers"); + expect(() => findMax(42)).toThrow("findMax requires an array of numbers"); + expect(() => findMax()).toThrow("findMax requires an array of numbers"); +}); From 872a29bbf97428183c472fe8208e4d6399c221c4 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:22:25 +0100 Subject: [PATCH 14/55] Add test for finding the maximum number in an array with positive and negative values --- Sprint-1/implement/max.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index f92bcc7ff..2f136ebfe 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -30,6 +30,9 @@ test("given an array with one number, returns that number", () => { // Given an array with both positive and negative numbers // When passed to the max function // Then it should return the largest number overall +test("given positive and negative numbers, return the largest overall", () => { + expect(findMax([-5, 10, -20, 3])).toBe(10); +}); // Given an array with just negative numbers // When passed to the max function From 6db374285a4fabba3f6450d9d7abba8c19bd6e68 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:23:45 +0100 Subject: [PATCH 15/55] Add test for finding the closest number to zero in an array of negative numbers --- Sprint-1/implement/max.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 2f136ebfe..0518b8fbe 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -37,6 +37,9 @@ test("given positive and negative numbers, return the largest overall", () => { // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero +test("given only negative numbers, returns the one closest to zero", () => { + expect(findMax([-8, -2, -30])).toBe(-2); +}) // Given an array with decimal numbers // When passed to the max function From 82f5c3af88dce97bf357ee91724693b08966e577 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:27:44 +0100 Subject: [PATCH 16/55] Add test for finding the largest decimal number in an array --- Sprint-1/implement/max.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 0518b8fbe..2066115ea 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -44,6 +44,9 @@ test("given only negative numbers, returns the one closest to zero", () => { // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number +test("given decimal numbers, returns the largest decimal", () => { + expect(findMax([1.5, 2.7, 2.65])).toBe(2.7); +}) // Given an array containing a value that isn't a number // When passed to the max function From 7aaff3c19356647f03fe0f180a146ef925d0c6f2 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:39:36 +0100 Subject: [PATCH 17/55] Add test for handling non-number elements in sum function --- Sprint-1/implement/sum.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index a288e0f0a..ad4e38cec 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -30,6 +30,9 @@ test.todo("given an empty array, returns 0") // Given an array containing a value that isn't a number // When passed to the sum function // Then it should throw Error("sum requires an array of numbers") +test("given an array with a non-number, throws an error", () => { + expect(() => sum(["hey", 10, "hi", 60, 10])).toThrow("sum requires an array of numbers"); +}); // Given something that isn't an array at all, such as "hey", 42 or no argument // When passed to the sum function From 02c2e87325e01f71a0f3448738eb8a65c553b706 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:43:50 +0100 Subject: [PATCH 18/55] Add error handling for non-array inputs in sum function --- Sprint-1/implement/sum.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..a70c70c9e 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,7 @@ function sum(elements) { + if (!Array.isArray(elements)) { + throw new Error("sum requires an array of numbers"); + } } module.exports = sum; From 44bf4cf1cfd51b82d0d3417a00871198b0ccb714 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:45:06 +0100 Subject: [PATCH 19/55] Implement test for returning 0 when given an empty array in sum function --- Sprint-1/implement/sum.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index ad4e38cec..f713b0f7e 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -13,7 +13,9 @@ const sum = require("./sum.js"); // Given an empty array // When passed to the sum function // Then it should return 0 -test.todo("given an empty array, returns 0") +test("given an empty array, returns 0", () => { + expect(sum([])).toBe(0); +}); // Given an array with just one number // When passed to the sum function From 0a3d100e15bf39d23fc610805f7d3c4d04efc41d Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:46:02 +0100 Subject: [PATCH 20/55] Refactor sum function to improve error handling and ensure input is an array of numbers --- Sprint-1/implement/sum.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index a70c70c9e..b76d7e492 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -2,6 +2,17 @@ function sum(elements) { if (!Array.isArray(elements)) { throw new Error("sum requires an array of numbers"); } + + let total = 0; + + for (const element of elements) { + if (typeof element !== "number") { + throw new Error("sum requires an array of numbers"); + } + total += element; + } + + return total; } module.exports = sum; From 5506d62a16d3ab28e12ce8a18b13ea68b347895a Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:49:06 +0100 Subject: [PATCH 21/55] Add test for handling non-array inputs in sum function --- Sprint-1/implement/sum.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index f713b0f7e..d75fc45dc 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -39,3 +39,8 @@ test("given an array with a non-number, throws an error", () => { // Given something that isn't an array at all, such as "hey", 42 or no argument // When passed to the sum function // Then it should throw Error("sum requires an array of numbers") +test("given something that is not an array, throws an error", () => { + expect(() => sum("hey")).toThrow("sum requires an array of numbers"); + expect(() => sum(42)).toThrow("sum requires an array of numbers"); + expect(() => sum()).toThrow("sum requires an array of numbers"); +}); \ No newline at end of file From 1507d42454159d6b9b001c5e2f18cdf2a6ccd7b2 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:50:36 +0100 Subject: [PATCH 22/55] Add test for handling single number input in sum function --- Sprint-1/implement/sum.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index d75fc45dc..a45a23019 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -20,6 +20,9 @@ test("given an empty array, returns 0", () => { // Given an array with just one number // When passed to the sum function // Then it should return that number +test("given an array with just one number, returns that number", () => { + expect(sum([7])).toBe(7); +}) // Given an array containing negative numbers // When passed to the sum function From cc8664c9d5c21d1081fc399dc85dc13d41c76ebe Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:52:21 +0100 Subject: [PATCH 23/55] Add test for handling negative numbers in sum function --- Sprint-1/implement/sum.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index a45a23019..65184e53b 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -22,11 +22,15 @@ test("given an empty array, returns 0", () => { // Then it should return that number test("given an array with just one number, returns that number", () => { expect(sum([7])).toBe(7); -}) +}); // Given an array containing negative numbers // When passed to the sum function // Then it should still return the correct total sum +test("given an array with negative numbers, returns the correct total", () => { + expect(sum([10, -4, -6])).toBe(0); + expect(sum([-1, -2, -3])).toBe(-6); +}); // Given an array with decimal/float numbers // When passed to the sum function From c2294372bfeacc59b3189a715dc1163f73838cff Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:54:21 +0100 Subject: [PATCH 24/55] Add test for handling decimal numbers in sum function --- Sprint-1/implement/sum.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index 65184e53b..3cec499bb 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -35,6 +35,10 @@ test("given an array with negative numbers, returns the correct total", () => { // Given an array with decimal/float numbers // When passed to the sum function // Then it should return the correct total sum +test("given an array with decimal numbers, returns the correct total", () => { + expect(sum([1.5, 2.5, 3])).toBe(7); + expect(sum([0.1, 0.2])).toBe(-0.3); +}); // Given an array containing a value that isn't a number // When passed to the sum function From 6b578bf4629f16209ac8d5d4e9fe80a585a211cd Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:56:05 +0100 Subject: [PATCH 25/55] Fix test for decimal numbers in sum function to use toBeCloseTo for precision --- Sprint-1/implement/sum.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index 3cec499bb..ef28a5b3e 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -37,7 +37,7 @@ test("given an array with negative numbers, returns the correct total", () => { // Then it should return the correct total sum test("given an array with decimal numbers, returns the correct total", () => { expect(sum([1.5, 2.5, 3])).toBe(7); - expect(sum([0.1, 0.2])).toBe(-0.3); + expect(sum([0.1, 0.2])).toBeCloseTo(-0.3); }); // Given an array containing a value that isn't a number From 4b21f36c26c70ba5c2365833bef70f98ed28182d Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Thu, 22 Oct 2026 18:57:01 +0100 Subject: [PATCH 26/55] Fix test for decimal numbers in sum function to return correct total --- Sprint-1/implement/sum.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index ef28a5b3e..af3587116 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -37,7 +37,7 @@ test("given an array with negative numbers, returns the correct total", () => { // Then it should return the correct total sum test("given an array with decimal numbers, returns the correct total", () => { expect(sum([1.5, 2.5, 3])).toBe(7); - expect(sum([0.1, 0.2])).toBeCloseTo(-0.3); + expect(sum([0.1, 0.2])).toBeCloseTo(0.3); }); // Given an array containing a value that isn't a number From 6fc8984af16150f6d109f22a4c6b460ccdf0b4d4 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 15:27:08 +0100 Subject: [PATCH 27/55] Implement export command for dedupe function --- Sprint-1/implement/dedupe.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..1507d0c66 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,5 @@ -function dedupe() {} +function dedupe() { + +} + +module.exports = dedupe; From fb39a6b51833ea5deb15b49dd6e97173a0f9ebf8 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 15:35:43 +0100 Subject: [PATCH 28/55] Implement test for dedupe function to handle empty array case --- Sprint-1/implement/dedupe.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index d7c8e3d8e..8f013a687 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -16,7 +16,9 @@ E.g. dedupe([1, 2, 1]) returns [1, 2] // Given an empty array // When passed to the dedupe function // Then it should return an empty array -test.todo("given an empty array, it returns an empty array"); +test("given an empty array, it returns an empty array", () => { + expect(dedupe([])).toEqual([]); +}); // Given an array with no duplicates // When passed to the dedupe function From 4ee500d6c21e23e5b14e9195cabeffd582c11e80 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 15:42:36 +0100 Subject: [PATCH 29/55] Implement dedupe function --- Sprint-1/implement/dedupe.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 1507d0c66..8734e7d65 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,5 +1,7 @@ function dedupe() { - + const uniqueItems = []; + + return uniqueItems; } module.exports = dedupe; From 6d78cdb7c9b119a9250cc3434b788fc20d682f64 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 15:43:27 +0100 Subject: [PATCH 30/55] Implement test for dedupe function to handle arrays with no duplicates --- Sprint-1/implement/dedupe.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 8f013a687..a6f19af5d 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -23,6 +23,13 @@ test("given an empty array, it returns an empty array", () => { // Given an array with no duplicates // When passed to the dedupe function // Then it should return a copy of the original array +test("given an array with no duplicates, it returns a copy of the original array", () => { + const input = [1, 2, 3, 4, 5]; + const result = dedupe(input); + + expect(result).toEqual([1, 2, 3, 4, 5]); + expect(result).not.toBe(input); +}); // Given an array of strings or numbers // When passed to the dedupe function From 71305974b25bfeec7846f5b5c8aa60186cf55914 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 15:47:29 +0100 Subject: [PATCH 31/55] Refactor dedupe function to accept an array parameter and iterate through its items --- Sprint-1/implement/dedupe.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 8734e7d65..8d49349c1 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,6 +1,11 @@ -function dedupe() { +function dedupe(originalArray) { const uniqueItems = []; + for (let i = 0; i < originalArray.length; i++) { + const currentItem = originalArray[i]; + uniqueItems.push(currentItem); + } + return uniqueItems; } From b3bd915063461580d68c0ffec3c710507eab9ac3 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 15:53:56 +0100 Subject: [PATCH 32/55] Add test for dedupe function to handle arrays with duplicate strings --- Sprint-1/implement/dedupe.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index a6f19af5d..651ad6ef9 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -35,3 +35,6 @@ test("given an array with no duplicates, it returns a copy of the original array // When passed to the dedupe function // Then it should return a new array with duplicates removed while preserving the // first occurrence of each element from the original array. +test("given an array of strings with duplicates, it removes them and keeps the first occurrence", () => { + expect(dedupe(["a", "a", "b", "b", "b", "c"])).toEqual(["a", "b", "c"]); +}); From aafec32d78325dc9cb7f57316e311caa16d924a7 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 15:58:01 +0100 Subject: [PATCH 33/55] Refactor dedupe function to prevent adding duplicates to the uniqueItems array --- Sprint-1/implement/dedupe.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 8d49349c1..3bd620ed4 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -3,7 +3,11 @@ function dedupe(originalArray) { for (let i = 0; i < originalArray.length; i++) { const currentItem = originalArray[i]; - uniqueItems.push(currentItem); + const alreadyInArray = uniqueItems.includes(currentItem); + + if (alreadyInArray === false) { + uniqueItems.push(currentItem); + } } return uniqueItems; From 70f312ce0d131b3d19ad3264f08fabd5e0f14697 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:02:07 +0100 Subject: [PATCH 34/55] Add test for dedupe function to handle arrays of numbers with duplicates --- Sprint-1/implement/dedupe.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 651ad6ef9..9e8bcdc78 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -38,3 +38,8 @@ test("given an array with no duplicates, it returns a copy of the original array test("given an array of strings with duplicates, it removes them and keeps the first occurrence", () => { expect(dedupe(["a", "a", "b", "b", "b", "c"])).toEqual(["a", "b", "c"]); }); + +test("given an array of numbers with duplicates, it removes them and keeps the first occurrence", () => { + expect(dedupe([1, 2, 2, 3, 3, 3, 4, 4, 5, 5])).toEqual([1, 2, 3, 4, 5]); + expect(dedupe([5, 5, 2, 1, 1,])).toEqual([5, 2, 1]); +}); From 6f4c2d40fe1688f526fcd5a60785cea0205e894a Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:19:00 +0100 Subject: [PATCH 35/55] Implement test for calculateMean function to verify mean calculation for an array of numbers --- Sprint-1/implement/mean.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 847b88676..eeb709dec 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -22,8 +22,9 @@ const calculateMean = require("./mean.js"); // Given an array of numbers // When passed to calculateMean // Then it should return their mean -// Delete this test.todo and replace it with a test. -test.todo("given [1, 2, 6], returns 3"); +test("given [1, 2, 6], returns 3", () => { + expect(calculateMean([1, 2, 6])).toBe(3); +}); // Given an array with a single number // When passed to calculateMean From f96c928f259f28c5af2523ac8d39131014651d72 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:19:37 +0100 Subject: [PATCH 36/55] Implement calculateMean function to compute the average of an array of numbers --- Sprint-1/implement/mean.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index 36909ea1f..b0ebde72a 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -1,3 +1,11 @@ -function calculateMean(list) {} +function calculateMean(list) { + let total = 0; + + for (let i = 0; i < list.length; i++) { + total += list[i]; + } + + return total / list.length; +} module.exports = calculateMean; From 9b1afc76a10c75c5287086fb9255aab527b187a7 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:35:27 +0100 Subject: [PATCH 37/55] Add tests for calculateMean function to handle single numbers, negative numbers, and decimal numbers --- Sprint-1/implement/mean.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index eeb709dec..df662e995 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -29,15 +29,27 @@ test("given [1, 2, 6], returns 3", () => { // Given an array with a single number // When passed to calculateMean // Then it should return that number +test("given [7], return 7", () => { + expect(calculateMean([7])).toBe(7); +}); // Given an array containing negative or decimal numbers // When passed to calculateMean // Then it should return the correct mean +test("given an array of negative numbers, return the correct mean", () => { + expect(calculateMean([-1, -3, -5])).toBe(-3); +}); + +test("given an array of decimal numbers, return the correct mean", () => { + expect(calculateMean([1.5, 2.5])).toBe(2); + expect(calculateMean([0.1, 0.2])).toBeCloseTo(0.15); +}); // Given an empty array // When passed to calculateMean // Then it should throw Error("calculateMean requires a non-empty array") + // Given a value that isn't an array, e.g. "banana", 42, null or {} // When passed to calculateMean // Then it should throw Error("calculateMean requires an array of numbers") From 84122b3aa98cf57ab0902fdb9b21d2858bbc4336 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:35:49 +0100 Subject: [PATCH 38/55] Add test for calculateMean function to verify error handling for empty array --- Sprint-1/implement/mean.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index df662e995..574895197 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -48,7 +48,9 @@ test("given an array of decimal numbers, return the correct mean", () => { // Given an empty array // When passed to calculateMean // Then it should throw Error("calculateMean requires a non-empty array") - +test("given an empty array, throws an error", () => { + expect(() => calculateMean([])).toThrow("calculateMean requires a non-empty array"); +}); // Given a value that isn't an array, e.g. "banana", 42, null or {} // When passed to calculateMean From 7eeab4105675711413dbc84a4efbfa25a34c0cde Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:37:21 +0100 Subject: [PATCH 39/55] Add error handling to calculateMean function for empty arrays --- Sprint-1/implement/mean.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index b0ebde72a..aa7487bf2 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -1,4 +1,9 @@ function calculateMean(list) { + + if (list.length === 0) { + throw new Error("calculateMean requires a non-empty array"); + } + let total = 0; for (let i = 0; i < list.length; i++) { From bece9ade3ce77c60a79a38063f09a80688bf3bcf Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:42:02 +0100 Subject: [PATCH 40/55] Add tests for calculateMean function to handle non-array inputs --- Sprint-1/implement/mean.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 574895197..c146e2f9d 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -55,6 +55,21 @@ test("given an empty array, throws an error", () => { // Given a value that isn't an array, e.g. "banana", 42, null or {} // When passed to calculateMean // Then it should throw Error("calculateMean requires an array of numbers") +test("given a value that is not an array, throws an error", () => { + expect(() => calculateMean("banana")).toThrow("calculateMean requires an array of numbers"); +}); + +test("given a value that is not an array, throws an error", () => { + expect(() => calculateMean(42)).toThrow("calculateMean requires an array of numbers"); +}); + +test("given a value that is not an array, throws an error", () => { + expect(() => calculateMean(null)).toThrow("calculateMean requires an array of numbers"); +}); + +test("given a value that is not an array, throws an error", () => { + expect(() => calculateMean({})).toThrow("calculateMean requires an array of numbers"); +}); // Given no argument at all // When passed to calculateMean From c0a278aab23048f1539f121206f45e009297bddf Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:43:44 +0100 Subject: [PATCH 41/55] Add input validation to calculateMean function for non-array inputs --- Sprint-1/implement/mean.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index aa7487bf2..15a089a9a 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -1,9 +1,12 @@ function calculateMean(list) { + if(!Array.isArray(list)) { + throw new Error("calculateMean requires an array of numbers"); + } if (list.length === 0) { throw new Error("calculateMean requires a non-empty array"); } - + let total = 0; for (let i = 0; i < list.length; i++) { From 0bb1418f47e6c936d8d43e9fd8f7fb1bb23e56b0 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:44:51 +0100 Subject: [PATCH 42/55] Add test for calculateMean function to handle no arguments --- Sprint-1/implement/mean.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index c146e2f9d..094286135 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -74,6 +74,9 @@ test("given a value that is not an array, throws an error", () => { // Given no argument at all // When passed to calculateMean // Then it should throw Error("calculateMean requires an array of numbers") +test("given no argument at all, throws an error", () => { + expect(() => calculateMean()).toThrow("calculateMean requires an array of numbers"); +}); // Given an array containing a non-number value, e.g. [1, "2", 3] // When passed to calculateMean From 55521a985690db9bf4436aee00faa103e8fb0372 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:49:40 +0100 Subject: [PATCH 43/55] Add test for calculateMean function to handle non-number values in array --- Sprint-1/implement/mean.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 094286135..c3723cb90 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -81,3 +81,6 @@ test("given no argument at all, throws an error", () => { // Given an array containing a non-number value, e.g. [1, "2", 3] // When passed to calculateMean // Then it should throw Error("calculateMean requires an array of numbers") +test("given an array with a non-number, throws an error", () => { + expect(() => calculateMean([7, "2", 5])).toThrow("calculateMean requires an array of numbers"); +}); From cd600e26fa65593c81d0da25984488ac69dd4db7 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 16:52:38 +0100 Subject: [PATCH 44/55] Add input validation for array elements in calculateMean function --- Sprint-1/implement/mean.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index 15a089a9a..86d340ecd 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -10,6 +10,9 @@ function calculateMean(list) { let total = 0; for (let i = 0; i < list.length; i++) { + if (typeof list[i] !== "number") { + throw new Error("calculateMean requires an array of numbers"); + } total += list[i]; } From 0ab70f6f26c6011b5f1528bb673274678067b13e Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 17:06:25 +0100 Subject: [PATCH 45/55] Implement test for describeMedian function to validate median calculation --- Sprint-1/implement/describe-median.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index e7d18a264..431773052 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -21,7 +21,9 @@ const describeMedian = require("./describe-median.js"); // When passed to describeMedian // Then it should return "The median is " followed by the median // Delete this test.todo and replace it with a test. -test.todo('given [1, 2, 3], returns "The median is 2"'); +test('given [1, 2, 3], returns "The median is 2"', () => { + expect(describeMedian([1, 2, 3])).toBe("The median is 2"); +}); // Given an empty array // When passed to describeMedian From 3cd361186dd0fe523c45dabfcf2b59a4f2e4f298 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 17:13:21 +0100 Subject: [PATCH 46/55] Implement describeMedian function to return median value as a string --- Sprint-1/implement/describe-median.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/describe-median.js b/Sprint-1/implement/describe-median.js index 3381cfc0a..2d21a02eb 100644 --- a/Sprint-1/implement/describe-median.js +++ b/Sprint-1/implement/describe-median.js @@ -20,6 +20,9 @@ function calculateMedian(list) { } // Implement this function. See describe-median.test.js for the acceptance criteria. -function describeMedian(list) {} +function describeMedian(list) { + const median = calculateMedian(list); + return `The median is ${median}`; +} module.exports = describeMedian; From 783326ccb26fd7a3396b4f3f9c8ff79a2e2d1922 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 17:21:46 +0100 Subject: [PATCH 47/55] Add tests for empty array cases --- Sprint-1/implement/describe-median.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index 431773052..4097d59a1 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -28,6 +28,9 @@ test('given [1, 2, 3], returns "The median is 2"', () => { // Given an empty array // When passed to describeMedian // Then it should return "Could not calculate a median: calculateMedian requires a non-empty array" +test('given an empty array, returns "Could not calculate a median: calculateMedian requires a non-empty array"', () => { + expect(describeMedian([])).toBe("Could not calculateMedian: calculateMedian requires a non-empty array"); +}); // Given something that isn't an array of numbers, e.g. "banana" // When passed to describeMedian From b9f0e907e9b6dd66b24297c399f932514c3a44c9 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 17:22:08 +0100 Subject: [PATCH 48/55] Add error handling to describeMedian function for invalid input --- Sprint-1/implement/describe-median.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/describe-median.js b/Sprint-1/implement/describe-median.js index 2d21a02eb..a563b79b9 100644 --- a/Sprint-1/implement/describe-median.js +++ b/Sprint-1/implement/describe-median.js @@ -21,8 +21,12 @@ function calculateMedian(list) { // Implement this function. See describe-median.test.js for the acceptance criteria. function describeMedian(list) { - const median = calculateMedian(list); - return `The median is ${median}`; + try { + const median = calculateMedian(list); + return `The median is ${median}`; + } catch (error) { + return "Could not calculate median: " + error.message; + } } module.exports = describeMedian; From 74b3e7789bf5daaed7551c056e7595ea36883cb2 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 17:24:19 +0100 Subject: [PATCH 49/55] Fix test typo in error message for empty array case --- Sprint-1/implement/describe-median.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index 4097d59a1..9091a3b7c 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -29,9 +29,10 @@ test('given [1, 2, 3], returns "The median is 2"', () => { // When passed to describeMedian // Then it should return "Could not calculate a median: calculateMedian requires a non-empty array" test('given an empty array, returns "Could not calculate a median: calculateMedian requires a non-empty array"', () => { - expect(describeMedian([])).toBe("Could not calculateMedian: calculateMedian requires a non-empty array"); + expect(describeMedian([])).toBe("Could not calculate median: calculateMedian requires a non-empty array"); }); // Given something that isn't an array of numbers, e.g. "banana" // When passed to describeMedian // Then it should return "Could not calculate a median: calculateMedian requires an array of numbers" + From c08e1093a3ae2e3dea52d4970e8373ef402c8bb3 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 17:31:43 +0100 Subject: [PATCH 50/55] Add test for non-number value of array case in describeMedian and fix typo --- Sprint-1/implement/describe-median.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index 9091a3b7c..7d4ee8f1c 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -29,10 +29,12 @@ test('given [1, 2, 3], returns "The median is 2"', () => { // When passed to describeMedian // Then it should return "Could not calculate a median: calculateMedian requires a non-empty array" test('given an empty array, returns "Could not calculate a median: calculateMedian requires a non-empty array"', () => { - expect(describeMedian([])).toBe("Could not calculate median: calculateMedian requires a non-empty array"); + expect(describeMedian([])).toBe("Could not calculate a median: calculateMedian requires a non-empty array"); }); // Given something that isn't an array of numbers, e.g. "banana" // When passed to describeMedian // Then it should return "Could not calculate a median: calculateMedian requires an array of numbers" - +test('given something that is not an array, returns "Could not calculate a median: calculateMedian requires an array of numbers"', () => { + expect(describeMedian("banana")).toBe("Could not calculate a median: calculateMedian requires an array of numbers"); +}); From 435bc33724f89dd2413e4e5baddf2a0ad5688a17 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 17:34:45 +0100 Subject: [PATCH 51/55] Fix typo in error message for median calculation failure --- Sprint-1/implement/describe-median.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/implement/describe-median.js b/Sprint-1/implement/describe-median.js index a563b79b9..492dba77c 100644 --- a/Sprint-1/implement/describe-median.js +++ b/Sprint-1/implement/describe-median.js @@ -25,7 +25,7 @@ function describeMedian(list) { const median = calculateMedian(list); return `The median is ${median}`; } catch (error) { - return "Could not calculate median: " + error.message; + return "Could not calculate a median: " + error.message; } } From 068ad9dece6688dba46ca409064c67a64fbf2c20 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 17:51:08 +0100 Subject: [PATCH 52/55] Refactor includes function to use for...of loop for improved readability --- Sprint-1/refactor/includes.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..8c9ae2e66 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,8 +1,7 @@ // Refactor the implementation of includes to use a for...of loop function includes(list, target) { - for (let index = 0; index < list.length; index++) { - const element = list[index]; + for (const element of list) { if (element === target) { return true; } From 3f5b5d314856500f12bd11616626cf769e53d267 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 19:13:38 +0100 Subject: [PATCH 53/55] Update input data for aoc-2018-day1 with new values and formatting adjustments --- Sprint-1/stretch/aoc-2018-day1/input.txt | 1476 +++++++++++----------- 1 file changed, 759 insertions(+), 717 deletions(-) diff --git a/Sprint-1/stretch/aoc-2018-day1/input.txt b/Sprint-1/stretch/aoc-2018-day1/input.txt index 1ffa65fc8..80150a795 100644 --- a/Sprint-1/stretch/aoc-2018-day1/input.txt +++ b/Sprint-1/stretch/aoc-2018-day1/input.txt @@ -1,951 +1,993 @@ ++3 ++15 +-1 +-18 ++3 -10 --12 -+1 -+14 -+11 --19 --4 -+10 ++3 +10 --12 --13 --10 -8 +-20 ++13 +11 -+3 +-21 -10 -+8 -+5 --14 -+7 -+12 -+12 -+14 --1 -+17 --5 -+9 --15 -+8 -16 -+9 -+6 -+17 --11 +-2 +-6 +19 -+11 --9 --1 -8 --16 --5 -+6 -+2 -+6 +12 -+15 -+16 --6 --8 --5 -+11 +-13 ++4 -9 -+19 -+19 --5 --12 --17 -20 -+9 --6 --2 -+20 -+15 --8 ++12 +15 -+19 --5 +-17 +-18 ++11 -17 -9 -+1 +-12 -9 --11 --19 --1 --15 -+18 --4 -+19 +3 -+21 -+5 --1 -+8 -+9 +9 --16 -+17 --15 +-6 +18 -+14 -+8 --13 --2 --15 -+13 -+19 --13 -+5 -+16 +16 -+7 -+8 --19 -+3 --12 -+18 --16 --19 ++9 +-11 +-1 +8 +-20 ++17 +-3 -16 -+20 -+15 --5 --17 +-7 ++10 ++6 ++3 +15 -+14 ++3 -2 -+18 ++9 +-8 -6 ++11 +5 -+16 -+13 ++24 ++10 ++4 -8 --9 --1 ++2 ++13 +-16 +13 -+18 --2 -+16 --4 -+19 -+6 -+14 --6 -16 --10 --5 --15 +11 -+10 -+18 -+8 --2 -+15 --9 +7 -+10 -+9 --6 -+1 --17 --12 -+19 -+14 -9 --18 -+20 -+12 -+10 -+14 -+6 -+9 --18 -+4 -+15 -+15 -+3 -+9 --4 --19 -+8 -+16 -+19 +-13 -12 ++17 +-4 +-5 -1 +16 -+11 -+13 --8 ++22 ++8 ++12 ++9 ++2 +-3 +-5 ++12 +4 ++4 ++8 +18 -+10 ++9 +-14 -11 -+18 --8 -+19 --4 -5 --12 --3 --10 -11 ++15 -18 -7 -+3 -+14 -+18 -+2 --7 -12 -+14 -+12 -+13 --1 -+13 --1 -+15 -+13 --1 --17 --4 -+17 --3 -+13 ++1 +5 --19 +-18 ++14 +-13 +-10 +17 -+10 -+6 --15 -+11 -+16 ++8 +11 +-12 +20 -+19 +-16 ++22 +5 --11 --2 --12 --6 --11 --14 ++1 +-9 ++16 ++13 ++6 +5 -+10 --23 -+14 --11 -+22 --1 --14 --35 --23 -+11 ++7 +-4 +-4 +-7 ++16 +4 -+10 --6 +-1 +-15 +-11 +19 --5 -+4 --13 ++9 ++17 +-15 ++21 -7 ++4 +-16 +-3 +-9 ++4 +11 --24 --17 -+9 --17 ++12 +11 -+2 --4 --10 --24 ++7 ++12 +14 +-6 +-1 +-18 +-3 +-13 ++4 ++10 +-15 +-10 +-8 ++15 +15 +19 ++16 +-3 +-14 ++13 ++16 ++1 ++10 ++9 +7 +-11 +-19 ++2 +-3 ++10 -2 -+11 ++13 +-19 +-7 ++3 ++18 ++1 ++9 ++2 ++12 -13 +-9 +-7 +-15 +-18 +-6 +-1 -8 --8 +-12 ++19 +-1 -14 --17 -+6 -+8 +-6 -16 --18 +-4 +1 --21 --14 -+8 --2 -+20 ++4 +-22 -19 -+9 --15 --6 --7 +-2 +4 --3 ++18 -8 +-19 +-16 ++6 +16 +-7 ++4 ++8 +-20 +-11 +-11 ++20 +15 --26 -+18 --22 --16 --3 --17 ++19 ++30 ++19 ++19 +-11 -18 +4 -+5 -+3 ++1 ++21 +-9 +-9 ++12 ++18 -1 -+3 -+2 -+3 -+7 --5 -+20 --11 -+15 --6 --19 --24 -6 --20 -+13 --4 --18 -+15 -+9 -+16 +12 --5 +16 -+9 --4 --14 --9 --19 --5 --16 --16 -+5 --4 +12 ++3 ++1 +-9 -15 -15 --14 -+4 +-1 +-1 -18 --12 --4 +-32 +-11 +-17 +-20 ++4 ++14 +-1 ++16 ++20 ++53 ++19 ++16 ++14 ++14 +6 -+9 --12 +-8 +14 -+9 --6 +-17 +-5 +3 -+8 -+4 -+7 --14 ++14 +-3 -15 --18 -+12 +-10 -19 --14 --15 --16 -+15 --8 ++17 ++3 ++17 ++5 +14 --4 --21 -+7 --12 +-7 ++5 ++14 ++18 -2 --10 +-19 ++8 ++10 ++15 -6 -+14 -+14 --9 --14 --16 -+2 -+7 -+5 ++13 +-11 ++19 ++10 -15 -15 -+19 --16 --5 --16 --19 ++2 +-4 +-3 ++11 ++2 ++18 ++3 ++17 +9 --27 +-16 -8 +6 ++15 +-11 +-3 ++20 +-1 ++12 +1 --14 --9 --50 --9 --21 -+5 --20 --19 -+6 --11 -+6 -+1 --17 --14 --2 +8 --4 ++11 +-8 ++6 ++7 ++17 +-12 ++13 +-8 +16 -+1 --3 --9 -+20 +15 --22 --3 --13 +-8 -12 --25 ++7 +-12 +-18 +5 --13 --2 ++5 ++7 -8 --11 ++6 +-4 +-15 +17 -+3 --7 -+13 -+1 -+18 --13 -+1 -+7 -15 --43 --6 -10 +-1 ++17 ++18 +-21 +-19 -9 --20 --7 --8 ++19 ++16 ++18 +-5 -15 ++19 +-11 ++10 ++9 +-1 ++4 ++4 ++9 +-5 ++20 ++4 +-18 ++17 ++12 +-18 ++14 +-21 +-15 +-5 +-18 +-17 +-19 ++11 ++12 +-20 +-19 ++12 -9 -+13 --9 -+24 -+13 ++8 +-1 +-22 ++4 ++15 ++14 ++9 +-10 +-26 +-22 +-10 ++7 ++9 +-1 +-16 +-21 +-18 ++8 ++6 ++18 ++1 +5 ++11 ++18 ++6 ++20 +-7 +-10 +-5 ++33 +-21 -8 --15 --4 --4 --4 +-13 +-5 ++7 ++1 +-7 +-39 -14 --21 +-12 +16 -+15 -14 --20 --20 -15 --19 --41 ++4 ++2 ++12 +-11 +16 -+3 +8 --22 --30 -+8 -+40 +15 -+24 +-1 ++21 +-5 ++13 +-18 -7 -+22 -+10 -+15 -+9 -+28 -+14 +2 -+14 +-15 ++19 ++8 ++26 +-24 ++37 ++59 ++21 +-19 ++18 +6 -+17 -+1 -+30 +-11 ++15 +-2 +5 -2 -+46 -+24 -+46 --3 ++20 ++8 ++2 -7 -+35 ++18 +-8 +-1 +-8 ++3 ++17 ++12 ++18 ++2 +-8 ++3 ++40 ++3 ++21 ++5 +-1 ++15 ++2 +16 -+13 --21 -+28 -+13 --25 -+180 -+25 +-50 ++15 +5 ++21 +-31 +-17 +-15 +-10 -9 -+23 --5 -2 +-18 +-14 ++7 +-14 ++6 +-20 +-8 +13 --12 +-27 ++8 +2 --25 --5 -+18 --24 -+45 -+17 --7 -+22 --152 --11 -+4 -+50 -+129 +-16 ++3 -7 -+22 -+109 --56 -+80 -+29 --75060 +-6 ++23 ++31 ++52 +-6 +-1 ++2 +-54 +-42 +-6 ++18 ++2 ++1 +-29 ++36 +-42 ++7 +-146 -2 -14 -+7 --17 --5 -+6 +-13 ++19 +-8 ++19 +-15 +-18 +-4 +-18 +-1 ++2 -3 ++11 +-16 +-23 +-9 +-30 +-31 ++58 +18 +-19 ++45 ++11 ++14 +-16 +19 --14 +-10 ++17 ++12 +-2 +-8 ++19 +-50 ++8 +-114 +-40 +-62 +-153 +-60 ++12 +-23 +-40 +-87 ++377 +-79652 -12 --6 -+9 ++1 +-9 -5 --13 --6 +-12 +-14 ++9 -3 +-2 ++8 -15 -+13 -+3 -18 --11 -+16 --2 -+10 --14 --7 +19 --20 -+15 -+10 -+12 -+10 -+16 --11 -+14 --5 -+14 +-6 ++4 +-14 +-2 +-18 +-19 +-8 ++2 +11 --5 -+1 --13 +-19 +-11 ++5 +-3 ++4 +1 -+18 --10 -+25 -+13 --17 +-3 ++9 ++7 +15 --18 -+1 --6 --12 -+5 --7 -+18 +-9 +-2 -6 --18 --17 ++3 ++2 ++10 ++9 ++3 -5 +-4 ++12 ++15 +-6 +-11 +-9 -15 --1 --15 -+1 --12 -+9 -+16 -+8 -+5 -+1 +9 -+18 --13 --30 --27 -19 -+2 +-15 ++4 ++7 ++7 -16 ++15 +-4 -19 --10 +-8 +-11 -18 -+21 -+18 --5 -+14 -+9 --6 +-14 +-18 +-16 ++5 ++5 ++12 +-9 +-16 +2 +-6 +-2 ++20 +-13 +-9 -16 ++4 +-1 ++2 +-3 +-17 +-2 -11 +1 -+18 --4 -+19 -+7 +6 --8 -+25 --50 ++17 +-4 +-15 +-3 +-19 +6 --21 +-16 +-18 +-6 ++2 ++12 +-9 +6 --2 -+14 --11 -+10 ++7 +-6 ++7 -9 -+16 -+25 --61 +-18 +-3 ++10 -17 --14 ++11 ++16 ++16 ++6 +13 +-17 ++2 +3 --14 --4 --1 -+9 ++17 +-10 ++8 -1 --4 --5 -+7 +-9 -15 -+7 -+16 -+6 --2 --11 --11 --13 +11 ++2 +-14 ++7 -12 --13 --8 +-19 +-3 +-7 +-7 +-15 +-17 ++5 +3 --13 -+16 --1 --14 -+19 -+4 -+10 -+12 -+26 ++14 +6 -+4 -+24 --31 -+9 --10 --23 --13 -+3 --18 +-5 ++17 -9 --6 +-5 +1 --2 -+15 --10 --17 --17 -+15 -+9 -+4 -+19 --4 -+12 -+11 --25 +-8 +-13 ++7 ++17 +-12 +-14 +-18 ++10 +16 -+4 --2 -+39 -+49 -+9 -+96 -+4 -+19 -+3 -+11 -+25 +-3 +-19 ++7 ++14 +14 +11 --5 --26 --8 --16 -+11 -+2 -+2 -1 --10 --45 --160 --31 --3 --43 --18 -+19 -+3 -+4 -+11 ++18 -16 --19 --22 -+6 -+2 +-4 +10 --11 +-14 ++9 -17 -+7 +-1 ++4 +-14 +-16 +1 -+15 -+17 --19 -+6 --26 +-14 -7 --9 ++1 ++7 +-11 +-4 +-14 +19 +-11 ++8 ++14 ++8 +-15 +-18 +2 +-17 +-19 ++13 ++3 +6 --22 -+2 --8 -+5 ++8 +-10 +7 -+9 +-3 +-9 +8 ++12 +-4 ++15 ++7 ++10 ++11 +-10 +-20 -16 -+2 --19 ++11 +-1 +-21 +-13 -19 --3 +-15 +-15 +-7 ++10 ++19 +-17 +-6 +-10 +-13 ++12 +-18 ++16 ++10 +-13 ++12 +-1 ++12 ++12 ++10 +16 -+5 -+4 -18 --11 --19 +-5 +-10 +-13 +-7 ++19 ++14 ++18 +-2 +-4 +-13 ++14 ++18 +-7 ++11 +-13 +-21 +-12 ++14 +16 --15 +7 --1 --9 -19 -+11 --17 --5 ++16 +7 --11 ++2 +-5 ++1 ++19 +16 --19 -+5 -+21 --2 ++14 ++9 +12 +14 --7 -+18 -8 -+10 --11 +-28 ++13 ++11 ++13 -17 -+3 --13 +-21 ++15 +-37 +-11 +19 --3 -+10 -+17 -+17 --18 -+7 --2 --2 ++1 ++8 +12 --6 -+19 --20 +-1 +-27 +-21 +-19 +-21 ++15 +-24 +-7 +-11 +-17 -15 -11 --27 +-11 +8 -+18 -+9 --1 --2 -+19 -+7 -+12 -+32 -+14 -+13 -9 --14 -+20 -+18 +-9 -4 --49 -6 ++15 -10 --7 --4 --9 --6 --37 --21 --2 -+5 -+12 -+4 --33 --4 --13 --4 -+13 --19 --7 --16 --1 --1 +-3 ++19 ++9 +8 ++6 ++11 +-4 -14 +-1 ++3 -15 -+11 ++17 ++18 -10 --14 -22 +-15 ++14 ++6 +-14 -11 -+10 --3 -+7 ++4 +-18 ++5 +-16 +-9 +-13 ++14 ++3 +9 --15 -+16 --7 ++17 +-9 ++22 +-12 +-8 +-5 -1 -+2 +-6 +-6 +-19 ++17 ++9 ++28 +20 ++14 +11 --1 +6 ++7 -2 -+3 -+3 ++17 ++17 +-12 ++7 ++21 +-2 +-4 ++10 +2 ++12 +-19 +-22 +-8 -20 --10 -+11 --10 -+13 ++25 +-17 +-15 +-8 -1 -+20 -+7 -+7 -+5 -+1 -+4 --13 ++13 +-15 ++16 +15 --3 -+2 ++19 +-128 +-4 +-16 -4 --3 --1 +13 --15 --14 --2 --6 -+3 +-10 ++20 +-16 +-13 ++15 ++9 ++1 +-11 +-16 +13 --19 ++1 ++15 ++1 +-31 ++11 +-53 +-11 +-9 +-16 -11 -+8 --21 --2 --23 --18 -+20 +7 +6 --28 -+7 --33 +13 ++6 +-12 +-3 ++16 ++2 +-5 ++7 -16 --18 --10 --18 -+13 -+8 --14 ++17 -13 --2 -+4 --14 --7 --18 --20 --4 --5 +-9 ++15 +-3 ++13 +8 --4 -+16 -+21 -+20 ++5 -8 --14 +-1 +-5 +-21 ++25 ++23 ++12 ++1 -2 --14 --22 ++7 +-25 +-51 +-5 ++4 +14 -+36 -+32 --28 -+1 +-8 ++4 ++11 +-5 -21 +-14 ++9 +8 -+14 -+75784 \ No newline at end of file +-13 ++4 ++80915 \ No newline at end of file From d1b8c9387cdb8458641e16c95e2008def78ef8e5 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Fri, 23 Oct 2026 19:57:43 +0100 Subject: [PATCH 54/55] Implement frequency calculation logic and handle duplicate frequencies --- Sprint-1/stretch/aoc-2018-day1/solution.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sprint-1/stretch/aoc-2018-day1/solution.js b/Sprint-1/stretch/aoc-2018-day1/solution.js index e69de29bb..0466c3bab 100644 --- a/Sprint-1/stretch/aoc-2018-day1/solution.js +++ b/Sprint-1/stretch/aoc-2018-day1/solution.js @@ -0,0 +1,19 @@ +const fs = require("fs"); +const input = fs.readFileSync("input.txt", "utf8"); +const changes = input.trim().split("\n").map(Number); + +let frequency = 0; +const seen = new Set([0]); + +while (true) { + for (const change of changes) { + frequency += change; + if (seen.has(frequency)) { + console.log(frequency); + process.exit(0); + } + seen.add(frequency); + } +} + +console.log(total); \ No newline at end of file From de542e0e1aa2ad95c89a83f1fc044ba3a5da84e4 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 24 Oct 2026 16:31:07 +0100 Subject: [PATCH 55/55] Refactor loop structure for improved readability in frequency calculation --- Sprint-1/stretch/aoc-2018-day1/solution.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sprint-1/stretch/aoc-2018-day1/solution.js b/Sprint-1/stretch/aoc-2018-day1/solution.js index 0466c3bab..7e120a061 100644 --- a/Sprint-1/stretch/aoc-2018-day1/solution.js +++ b/Sprint-1/stretch/aoc-2018-day1/solution.js @@ -6,14 +6,14 @@ let frequency = 0; const seen = new Set([0]); while (true) { - for (const change of changes) { - frequency += change; - if (seen.has(frequency)) { - console.log(frequency); - process.exit(0); - } - seen.add(frequency); + for (const change of changes) { + frequency += change; + if (seen.has(frequency)) { + console.log(frequency); + process.exit(0); } + seen.add(frequency); + } } -console.log(total); \ No newline at end of file +console.log(total);