From 2071acd370db9ea32bb405122ebd6ed379ad8546 Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 15:50:29 +0000 Subject: [PATCH 01/42] fixed median calculation for odd and even arrays --- Sprint-1/fix/median.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 5c5b796e1..8cef4118e 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -7,8 +7,12 @@ function calculateMedian(list) { const middleIndex = Math.floor(list.length / 2); - const median = list.splice(middleIndex, 1)[0]; - return median; + + if (list.length % 2 === 0) { + return (list[middleIndex - 1] + list[middleIndex]) / 2; + } else { + return list[middleIndex]; + } } module.exports = calculateMedian; From 19742a76169f307c87cbd74a764edb702e04a41c Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 16:03:40 +0000 Subject: [PATCH 02/42] Sorted a copy before calculating the median --- Sprint-1/fix/median.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 8cef4118e..0f42cb652 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,12 +6,14 @@ // or contains values that aren't numbers (the function is expected to throw - see the tests). function calculateMedian(list) { - const middleIndex = Math.floor(list.length / 2); + const sortedList = [...list]; + sortedList.sort((a, b) => a - b); + const middleIndex = Math.floor(sortedList.length / 2); - if (list.length % 2 === 0) { - return (list[middleIndex - 1] + list[middleIndex]) / 2; + if (sortedList.length % 2 === 0) { + return (sortedList[middleIndex - 1] + sortedList[middleIndex]) / 2; } else { - return list[middleIndex]; + return sortedList[middleIndex]; } } From aca8e91ae2ed2b07758ff23092eb7bdf28568689 Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 16:14:16 +0000 Subject: [PATCH 03/42] Added a check in function to make sure the input is an array --- Sprint-1/fix/median.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 0f42cb652..e7b4d4bfb 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,6 +6,9 @@ // 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]; sortedList.sort((a, b) => a - b); const middleIndex = Math.floor(sortedList.length / 2); From 091e875b4420ff26ce9f3fab478191dedee5d824 Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 16:20:29 +0000 Subject: [PATCH 04/42] Added a a check in function for empty arrays --- 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 e7b4d4bfb..f0904dc7b 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -9,6 +9,10 @@ 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]; sortedList.sort((a, b) => a - b); const middleIndex = Math.floor(sortedList.length / 2); From c4d364885ce11ceab58c9c6f584101b02b19a914 Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 16:44:04 +0000 Subject: [PATCH 05/42] added check in function that the array only contains numbers --- 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 f0904dc7b..8a58f7c90 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -13,6 +13,10 @@ function calculateMedian(list) { if (list.length === 0) { throw new Error("calculateMedian requires a non-empty array"); } + + if (!list.every((number) => typeof number === "number")) { + throw new Error("calculateMedian requires an array of numbers"); + } const sortedList = [...list]; sortedList.sort((a, b) => a - b); const middleIndex = Math.floor(sortedList.length / 2); From fc92cc23b44153180ae3757b9c274a5917df6851 Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 17:42:10 +0000 Subject: [PATCH 06/42] removed duplicate values from arrays --- Sprint-1/implement/dedupe.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..16b3eb20b 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,18 @@ -function dedupe() {} +function dedupe(numbers) { + //function starts + const uniqueNumbers = []; + + for (let i = 0; i < numbers.length; i++) { + // for loop starts + const currentValue = numbers[i]; + + if (!uniqueNumbers.includes(currentValue)) { + // if statement starts + uniqueNumbers.push(currentValue); + } // if statement ends + } // for loop ends + + return uniqueNumbers; +} //function ends + +module.exports = dedupe; From a0786537ab04c00647b01d18e48469f5fb19138c Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 18:11:36 +0000 Subject: [PATCH 07/42] added describe median function --- Sprint-1/implement/describe-median.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/describe-median.js b/Sprint-1/implement/describe-median.js index 3381cfc0a..a56e3d7ba 100644 --- a/Sprint-1/implement/describe-median.js +++ b/Sprint-1/implement/describe-median.js @@ -1,5 +1,7 @@ // Don't change this function. function calculateMedian(list) { + + if (!Array.isArray(list)) { throw new Error("calculateMedian requires an array of numbers"); } @@ -20,6 +22,13 @@ function calculateMedian(list) { } // Implement this function. See describe-median.test.js for the acceptance criteria. -function describeMedian(list) {} +function describeMedian(list) { // opens function + try { // opens try statement + const median = calculateMedian(list); + return `The median is ${median}`; + } catch (error) { // opens catch + return "Could not calculate a median: " + error.message; + } +} //closes function module.exports = describeMedian; From e02094b0af140b22205fe52d77f658d682ec9f29 Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 21:33:06 +0000 Subject: [PATCH 08/42] Added tests for describeMedian --- Sprint-1/implement/describe-median.test.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index e7d18a264..0696112ee 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -21,12 +21,25 @@ 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])).toEqual("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 an error message", () => { + expect(describeMedian([])).toEqual( + "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 a string returns an error message", () => { + expect(describeMedian("banana")).toEqual( + "Could not calculate a median: calculateMedian requires an array of numbers" + ); +}); From 1875b30655d230b2a9423d8a6d863e43d8283442 Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 21:37:14 +0000 Subject: [PATCH 09/42] Ignore prep directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8ee70353f..ac74be127 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules **/.DS_Store .idea package-lock.json +/prep/ From f9a47c72794684f5172f5b4bbb448d67dbc5d66e Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 22:20:35 +0000 Subject: [PATCH 10/42] Implemented findMax function --- Sprint-1/implement/max.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..663218659 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,20 @@ function findMax(elements) { + if ( + !Array.isArray(elements) || + !elements.every((element) => typeof element === "number") + ) { + throw new Error("findMax requires an array of numbers"); + } + + let max = -Infinity; + + for (let i = 0; i < elements.length; i++) { + if (elements[i] > max) { + max = elements[i]; + } + } + + return max; } module.exports = findMax; From 1516690d3b716c8eb82eb13a7ebc9e8daad56799 Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 22:33:53 +0000 Subject: [PATCH 11/42] added empty and single-number tests for findMax --- Sprint-1/implement/max.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index ff3fbb5e5..137dba18e 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -16,11 +16,16 @@ 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, should return -Infinity", () => { + expect(findMax([])).toEqual(-Infinity); +}); // Given an array with one number // When passed to the max function // Then it should return that number +test("expects findMax with an array containing 7 to return 7", () => { + expect(findMax([7])).toEqual(7); +}); // Given an array with both positive and negative numbers // When passed to the max function From 445b260754f202ca71e64b0e49c83c2da9cf261b Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 22:44:28 +0000 Subject: [PATCH 12/42] Added test for both positive and negative numbers --- 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 137dba18e..f81eaa5bf 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -30,7 +30,9 @@ test("expects findMax with an array containing 7 to return 7", () => { // Given an array with both positive and negative numbers // When passed to the max function // Then it should return the largest number overall - +test("returns largest number given an array with both positive and negative numbers", () => { + expect(findMax([-5, -6, 10, 4])).toEqual(10); +}); // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero From 4337038728888114455598d8ea359474669b61ea Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 22:47:38 +0000 Subject: [PATCH 13/42] Add test for array with negative numbers --- 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 f81eaa5bf..45d1983a9 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -36,7 +36,9 @@ test("returns largest number given an array with both positive and negative numb // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero - +test("returns largest number when given an array with negative numbers", () => { + expect(findMax([-4, -7, -9, -14])).toEqual(-4); +}); // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number From 6fd0acf23367d7928bf77216d67ee1627c8e0e5c Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 22:50:39 +0000 Subject: [PATCH 14/42] added test for decimal numbers --- 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 45d1983a9..64050f362 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -42,7 +42,9 @@ test("returns largest number when given an array with negative numbers", () => { // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number - +test("returns largest number when given an array of decimal numbers", () => { + expect(findMax([2.2, 4.3, 6.8, 9.4])).toEqual(9.4); +}); // 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") From 8490f09ae2a91bc4e3dd640e5db9e4df70155464 Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 22:56:40 +0000 Subject: [PATCH 15/42] added test for value that isnt a number --- Sprint-1/implement/max.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 64050f362..3ee02ba66 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -48,7 +48,11 @@ test("returns largest number when given an array of decimal numbers", () => { // 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 containing a value that isn't a number", () => { + expect(() => findMax([4, "hello", 5])).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 // Then it should throw Error("findMax requires an array of numbers") From 7b42dd0da6343f380f3a5b03bdc0337797ac4601 Mon Sep 17 00:00:00 2001 From: marscancode Date: Tue, 3 Nov 2026 23:03:54 +0000 Subject: [PATCH 16/42] Completed findMax tests --- Sprint-1/implement/max.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 3ee02ba66..21f25ffe7 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -56,3 +56,16 @@ test("given an array containing a value that isn't a number", () => { // 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 isn't an array at all", () => { + 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" + ); +}); \ No newline at end of file From 9f17e6dae044e93fce1f963b5a82a234ffa0cd37 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 11:41:45 +0000 Subject: [PATCH 17/42] added first test for calculateMean, it fails --- 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 847b88676..fbba037ba 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -23,7 +23,9 @@ const calculateMean = require("./mean.js"); // 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 the array [1,2,6], should return the number 3", () => { + expect(calculateMean([1, 2, 6])).toEqual(3); +}); // Given an array with a single number // When passed to calculateMean From 19d9c71134b99ea51ca10d9ff9764763d03c97f1 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 12:16:54 +0000 Subject: [PATCH 18/42] implemented function calculateMean --- Sprint-1/implement/mean.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index 36909ea1f..2490df14c 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -1,3 +1,9 @@ -function calculateMean(list) {} +function calculateMean(list) { + const sum = list.reduce((sum, number) => { + return sum + number; + }, 0); + + return sum / list.length; +} module.exports = calculateMean; From 063182ae15c176726f78c293a71d71950a788197 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 14:25:20 +0000 Subject: [PATCH 19/42] test to check wether calculateMean works given an array with a single number, it passes --- 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 fbba037ba..ccbb09751 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -30,6 +30,9 @@ test("given the array [1,2,6], should return the number 3", () => { // Given an array with a single number // When passed to calculateMean // Then it should return that number +test("given an array with a single number, should return 7", () => { + expect(calculateMean([7])).toEqual(7); +}); // Given an array containing negative or decimal numbers // When passed to calculateMean From 1b1468ed4c74e9c869cce8cf047fbd049df4f9cf Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 14:30:01 +0000 Subject: [PATCH 20/42] test to check how calculateMean handles an array of negative numbers, it passes --- 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 ccbb09751..4242df813 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -37,7 +37,9 @@ test("given an array with a single number, should return 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, should return -4", () => { + expect(calculateMean([-2, -4, -6])).toEqual(-4); +}); // Given an empty array // When passed to calculateMean // Then it should throw Error("calculateMean requires a non-empty array") From d90b2cf5a76807ed2d63ca530080f19f663e186b Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 14:34:24 +0000 Subject: [PATCH 21/42] test to check wether calculateMean handles an array of decimal numbers, it passes --- 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 4242df813..e6de86695 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -40,6 +40,9 @@ test("given an array with a single number, should return 7", () => { test("given an array of negative numbers, should return -4", () => { expect(calculateMean([-2, -4, -6])).toEqual(-4); }); +test("given an array of decimal numbers, should return 2.5", () => { + expect(calculateMean([1.5, 2.5, 3.5])).toEqual(2.5); +}); // Given an empty array // When passed to calculateMean // Then it should throw Error("calculateMean requires a non-empty array") From 7547c25742cc0fd3768bfa0925e97750ff72c9e7 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 14:45:42 +0000 Subject: [PATCH 22/42] added test to check wether calculateMean throws an error when given an empty array, it fails --- Sprint-1/implement/mean.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index e6de86695..b1595a3bc 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -46,7 +46,11 @@ test("given an array of decimal numbers, should return 2.5", () => { // Given an empty array // When passed to calculateMean // Then it should throw Error("calculateMean requires a non-empty array") - +test("given an empty array, should throw 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 // Then it should throw Error("calculateMean requires an array of numbers") From c87f412b932bd45e7491538482918534d077a08b Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 14:52:05 +0000 Subject: [PATCH 23/42] implemented calculateMean to handle empty arrays --- 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 2490df14c..4dc450b14 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -1,4 +1,7 @@ function calculateMean(list) { + if (list.length === 0) { + throw new Error("calculateMean requires a non-empty array"); + } const sum = list.reduce((sum, number) => { return sum + number; }, 0); From f24628a57218f4437b5fbf564275c10a44b35225 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 15:05:23 +0000 Subject: [PATCH 24/42] test to check if calculateMean throws an error when given a string instead of an array --- Sprint-1/implement/mean.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index b1595a3bc..a405e28d7 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -54,7 +54,11 @@ test("given an empty array, should throw 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 string instead of an array, should throw an error", () => { + expect(() => calculateMean("banana")).toThrow( + "calculateMean requires an array of numbers" + ); +}); // Given no argument at all // When passed to calculateMean // Then it should throw Error("calculateMean requires an array of numbers") From c5745352bba1624fa6d5a3af9d6035c7f0460de2 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 15:12:36 +0000 Subject: [PATCH 25/42] implemented calculateMean to handle a string, tests pass --- 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 4dc450b14..d6cee5447 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -1,4 +1,7 @@ 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"); } From c427aa2e052e6b3358b8f0d0f18179bad427e63b Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 15:21:17 +0000 Subject: [PATCH 26/42] added tests for calculateMean for invalid non-array values --- Sprint-1/implement/mean.test.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index a405e28d7..eae50dce6 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -54,10 +54,26 @@ test("given an empty array, should throw 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 string instead of an array, should throw an error", () => { +test("given a value that isn't an array, should throw an error", () => { expect(() => calculateMean("banana")).toThrow( "calculateMean requires an array of numbers" ); + + expect(() => calculateMean(42)).toThrow( + "calculateMean requires an array of numbers" + ); + + expect(() => calculateMean(null)).toThrow( + "calculateMean requires an array of numbers" + ); + + expect(() => calculateMean({})).toThrow( + "calculateMean requires an array of numbers" + ); + + expect(() => calculateMean()).toThrow( + "calculateMean requires an array of numbers" + ); }); // Given no argument at all // When passed to calculateMean From 108c621ed048b4fa2512a898eafeca628bdb5ec7 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 15:32:14 +0000 Subject: [PATCH 27/42] deleted duplicate empty array test --- Sprint-1/implement/mean.test.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index eae50dce6..1cb5788c9 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -75,10 +75,6 @@ test("given a value that isn't an array, should throw an error", () => { "calculateMean requires an array of numbers" ); }); -// Given no argument at all -// When passed to calculateMean -// Then it should throw Error("calculateMean requires an array of numbers") - // 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") From 03ec9391880688b6ccf1cbb32f75f6fcca3051e8 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 15:37:59 +0000 Subject: [PATCH 28/42] added test to check if calculateMedian throws an error when given an array with a non-number value --- Sprint-1/implement/mean.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 1cb5788c9..1b716ae38 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -78,3 +78,8 @@ test("given a value that isn't an array, should throw 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 containing a non-number value, should throw an error", () => { + expect(() => calculateMean([1, "2", 3])).toThrow( + "calculateMean requires an array of numbers" + ); +}); From 304895230c0ce34ce131536829cb2fba62908f92 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 15:45:16 +0000 Subject: [PATCH 29/42] implemented calculate mean to only take in arrays with number values --- 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 d6cee5447..f8e710d29 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -5,6 +5,9 @@ function calculateMean(list) { if (list.length === 0) { throw new Error("calculateMean requires a non-empty array"); } + if (!list.every((number) => typeof number === "number")) { + throw new Error("calculateMean requires an array of numbers"); + } const sum = list.reduce((sum, number) => { return sum + number; }, 0); From e6bec3a36aee120aa061f1149d2defb30db928c2 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 15:51:23 +0000 Subject: [PATCH 30/42] added test for empty sum array --- Sprint-1/implement/sum.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index a288e0f0a..40dc16336 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -13,8 +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([])).toEqual(0); +}); // Given an array with just one number // When passed to the sum function // Then it should return that number From 15f68c93ae63e830bbd6179af6a36c67e5dcc095 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:04:07 +0000 Subject: [PATCH 31/42] implemented the sum function using reduce, test passes --- Sprint-1/implement/sum.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..37c2c4ff5 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,7 @@ function sum(elements) { + const sum = elements.reduce((sum, number) => { + return number + sum; + }, 0); + return sum; } - module.exports = sum; From e4a79ce3cf704f2431ce6b6f9cfb0b2becfdfcaf Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:18:58 +0000 Subject: [PATCH 32/42] added test to check if an array with one number returns the number --- 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 40dc16336..9de668f27 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -19,6 +19,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 one number, returns that number", () => { + expect(sum([7])).toEqual(7); +}); // Given an array containing negative numbers // When passed to the sum function From 51a5109a0a88301f2abebcb6ced5624c20c53776 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:22:38 +0000 Subject: [PATCH 33/42] added test to check if sum can handle negative numbers --- 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 9de668f27..30b290b00 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -26,6 +26,9 @@ test("given an array with one number, returns that number", () => { // 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 sum", () => { + expect(sum([-4, -6, -2])).toEqual(-12); +}); // Given an array with decimal/float numbers // When passed to the sum function From 597c5f560b76ce2a42546e7260e476c0e709c94b Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:27:13 +0000 Subject: [PATCH 34/42] added test for sum with decimal numbers --- 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 30b290b00..0f3fd2532 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -33,6 +33,9 @@ test("given an array with negative numbers, returns the correct sum", () => { // 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 sum", () => { + expect(sum([2.5, 3.5, 5.5])).toEqual(11.5); +}); // Given an array containing a value that isn't a number // When passed to the sum function From 28a59d05e03fa5dce2c378d8322c116434d139e8 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:30:23 +0000 Subject: [PATCH 35/42] added test to check if sum throws an error when given an array containing a non-number --- 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 0f3fd2532..4568f78e7 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -40,7 +40,11 @@ test("given an array with decimal numbers, returns the correct sum", () => { // 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 containing a non-number, throws an error", () => { + expect(() => sum([10, "hello", 2])).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 // Then it should throw Error("sum requires an array of numbers") From 4e83c4c483f6c52d3032f99df6d02d4a01c08291 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:34:14 +0000 Subject: [PATCH 36/42] implemented sum function using reduce --- Sprint-1/implement/sum.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 37c2c4ff5..1e3465c03 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -5,3 +5,4 @@ function sum(elements) { return sum; } module.exports = sum; + From c9f77547955ae9c98b4f0a65afb648c03415b296 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:41:16 +0000 Subject: [PATCH 37/42] implemented sum function to throw an error if given an array containing a non-number --- Sprint-1/implement/sum.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 1e3465c03..70e1b9988 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,8 +1,10 @@ function sum(elements) { + if (!elements.every((element) => typeof element === "number")) { + throw new Error("sum requires an array of numbers"); + } const sum = elements.reduce((sum, number) => { return number + sum; }, 0); return sum; } module.exports = sum; - From 75d26abbda04091d55072313af485cc720dc9f58 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:47:25 +0000 Subject: [PATCH 38/42] added test for non-array input 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 4568f78e7..0378ddcfc 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -48,3 +48,7 @@ test("given an array containing 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 a non-array input, throws an error", () => { + expect(() => sum("hello")).toThrow("sum requires an array of numbers"); +}); From 9abe6cc91a05e5a2a8f45345387c94671ee693a1 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:52:14 +0000 Subject: [PATCH 39/42] implemented sum function to check array input if incorrect throw error --- Sprint-1/implement/sum.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 70e1b9988..9fde47645 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,8 +1,11 @@ function sum(elements) { + if (!Array.isArray(elements)) { + throw new Error("sum requires an array of numbers"); + } if (!elements.every((element) => typeof element === "number")) { throw new Error("sum requires an array of numbers"); } - const sum = elements.reduce((sum, number) => { +const sum = elements.reduce((sum, number) => { return number + sum; }, 0); return sum; From 80d443407f0aab7b92a310d1289dfb0802272269 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:57:08 +0000 Subject: [PATCH 40/42] Add tests for non-array and missing sum arguments --- 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 0378ddcfc..4ff06f55f 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -52,3 +52,7 @@ test("given an array containing a non-number, throws an error", () => { test("given a non-array input, throws an error", () => { expect(() => sum("hello")).toThrow("sum requires an array of numbers"); }); + +test("given no argument, throws an error", () => { + expect(() => sum()).toThrow("sum requires an array of numbers"); +}); From 9ea7f047bce9b9f8ebd894f0967c331bae9717c1 Mon Sep 17 00:00:00 2001 From: marscancode Date: Wed, 4 Nov 2026 16:59:52 +0000 Subject: [PATCH 41/42] added test for 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 4ff06f55f..94a78e0af 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -56,3 +56,6 @@ test("given a non-array input, throws an error", () => { test("given no argument, throws an error", () => { expect(() => sum()).toThrow("sum requires an array of numbers"); }); +test("given a number instead of an array, throws an error", () => { + expect(() => sum(42)).toThrow("sum requires an array of numbers"); +}); From 556c1a79d7cec92083d0d2a97ee8808d43ab65a2 Mon Sep 17 00:00:00 2001 From: marscancode Date: Thu, 5 Nov 2026 11:27:00 +0000 Subject: [PATCH 42/42] refactored includes to use a for...of loop, tests pass --- Sprint-1/refactor/includes.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..78bbc70b0 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,8 +1,6 @@ // 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; }