From 13fca372a61e682dba794ac9d25496488981fa0b Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 22:32:33 +0100 Subject: [PATCH 01/63] array of numbers fixed --- 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 5c5b796e1..ab00289d1 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 middleIndex = Math.floor(list.length / 2); const median = list.splice(middleIndex, 1)[0]; return median; From 010e59e07ae8795c4da26f7d55ad7d810c8f97dc Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 22:33:27 +0100 Subject: [PATCH 02/63] non empty array fixed --- 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 ab00289d1..b281b6db8 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 middleIndex = Math.floor(list.length / 2); const median = list.splice(middleIndex, 1)[0]; return median; From a88585938f50f6f4fe0c75a6e66cfc10198f6965 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 22:40:17 +0100 Subject: [PATCH 03/63] non list of array fixed --- Sprint-1/fix/median.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b281b6db8..1b5f6e2d2 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -12,7 +12,9 @@ function calculateMedian(list) { if (list.length === 0) { throw new Error("calculateMedian requires a non-empty array"); }; - + if (!list.every((item) => typeof item === "number")) { + throw new Error("calculateMedian requires an array of numbers"); + }; const middleIndex = Math.floor(list.length / 2); const median = list.splice(middleIndex, 1)[0]; return median; From cd959505c2f1a0194301be642c2d67ab0d325117 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 22:50:00 +0100 Subject: [PATCH 04/63] all test function fixed --- Sprint-1/fix/median.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 1b5f6e2d2..0f831c6ce 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -1,23 +1,20 @@ -// Fix this implementation -// Start by running the tests for this function -// If you're in the Sprint-1 directory, you can run `npm test -- fix` to run the tests in the fix directory - -// Hint: Please consider scenarios when 'list' isn't an array, is empty, -// 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"); - }; + } if (list.length === 0) { throw new Error("calculateMedian requires a non-empty array"); - }; + } if (!list.every((item) => typeof item === "number")) { throw new Error("calculateMedian requires an array of numbers"); - }; - const middleIndex = Math.floor(list.length / 2); - const median = list.splice(middleIndex, 1)[0]; - return median; + } + const sorted = [...list].sort((a, b) => a - b); + const middleIndex = Math.floor(sorted.length / 2); + if (sorted.length % 2 === 0) { + return (sorted[middleIndex - 1] + sorted[middleIndex]) / 2; + } + + return sorted[middleIndex]; } module.exports = calculateMedian; From 3cc7cf4553ffb7dcb30b6fbc3ca123f4f68b8be3 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:04:19 +0100 Subject: [PATCH 05/63] empty array return infinity --- 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..b4aa606e6 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([7])).toBe(7); +}); // Given an array with one number // When passed to the max function From 79f3284cc6642231feea79d780c3811797ef0857 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:05:37 +0100 Subject: [PATCH 06/63] empty array return infinity --- Sprint-1/implement/max.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index b4aa606e6..9a71d7dfc 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -17,7 +17,7 @@ const findMax = require("./max.js"); // Then it should return -Infinity // Delete this test.todo and replace it with a test. test("given an empty array, returns -Infinity", () => { - expect(findMax([7])).toBe(7); + expect(findMax([])).toBe(-infinity); }); // Given an array with one number From df508f30f7265ac5a8a2f869fb186eb72ee2563c Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:09:22 +0100 Subject: [PATCH 07/63] test given an array of one number --- Sprint-1/implement/max.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 9a71d7dfc..63de1f08a 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -20,6 +20,12 @@ test("given an empty array, returns -Infinity", () => { expect(findMax([])).toBe(-infinity); }); +test("given an array with one number, returns that number", () => { + expect(findMax([7])).toBe(7); +}); + + + // Given an array with one number // When passed to the max function // Then it should return that number From 523c22c68dab28afd38aa725361f3b6e13ee84b6 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:13:29 +0100 Subject: [PATCH 08/63] test largest 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 63de1f08a..db8ae4a0c 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -24,7 +24,9 @@ test("given an array with one number, returns that number", () => { expect(findMax([7])).toBe(7); }); - +test("returns the largest of positive and negative numbers", () => { + expect(findMax([-6, 5, -3, 8])).toBe(8) +}) // Given an array with one number // When passed to the max function From 92b41f3fdbb73f0538c694d65a2c970d03b1b6da Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:14:12 +0100 Subject: [PATCH 09/63] fix: correct syntax in test for largest of positive and negative numbers --- Sprint-1/implement/max.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index db8ae4a0c..114aadf3f 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -25,8 +25,8 @@ test("given an array with one number, returns that number", () => { }); test("returns the largest of positive and negative numbers", () => { - expect(findMax([-6, 5, -3, 8])).toBe(8) -}) + expect(findMax([-6, 5, -3, 8])).toBe(8); +}); // Given an array with one number // When passed to the max function From 55446f7e8f90b0635b0944e319b79e55d4ac396a Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:18:22 +0100 Subject: [PATCH 10/63] closest to zero for all negative numbers --- Sprint-1/implement/max.test.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 114aadf3f..581fa80c9 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -17,15 +17,19 @@ const findMax = require("./max.js"); // Then it should return -Infinity // Delete this test.todo and replace it with a test. test("given an empty array, returns -Infinity", () => { - expect(findMax([])).toBe(-infinity); + expect(findMax([])).toBe(-infinity); }); test("given an array with one number, returns that number", () => { - expect(findMax([7])).toBe(7); + expect(findMax([7])).toBe(7); }); test("returns the largest of positive and negative numbers", () => { - expect(findMax([-6, 5, -3, 8])).toBe(8); + expect(findMax([-6, 5, -3, 8])).toBe(8); +}); + +test("returns the closest to zero for all negatives", () => { + expect(findMax([-9, -2, -6])).toBe(-2); }); // Given an array with one number From 59800af8c812937b49b0644e4770663ee073fa72 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:21:12 +0100 Subject: [PATCH 11/63] closest to zero for all negative numbers --- Sprint-1/implement/max.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 581fa80c9..f9996c5be 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -32,6 +32,12 @@ test("returns the closest to zero for all negatives", () => { expect(findMax([-9, -2, -6])).toBe(-2); }); +test("returns the largest decimal number", () => { + expect(findMax([1.2, 3.8, 2.6])).toBe(3.8); +}); + + + // Given an array with one number // When passed to the max function // Then it should return that number From 01356bce2f252320fda550e7c38ddb42c3db40ef Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:22:11 +0100 Subject: [PATCH 12/63] test for largest decimal numbers --- 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 f9996c5be..533824415 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -38,6 +38,11 @@ test("returns the largest decimal number", () => { + + + + + // Given an array with one number // When passed to the max function // Then it should return that number From 8223706589c2d1c40d1537dc661f45bfcf4fe256 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:27:26 +0100 Subject: [PATCH 13/63] test containing non-numbers --- Sprint-1/implement/max.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 533824415..0c4908788 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -36,6 +36,10 @@ test("returns the largest decimal number", () => { expect(findMax([1.2, 3.8, 2.6])).toBe(3.8); }); +test("throws for an array containing a non-number", () => { + expect(() => findMax(["hey", 10])).toThrow(new Error("findMax requires an array of numbers")); +}); + From 40ab19508762e8b7b4cba9da540089b69cb94da2 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:31:07 +0100 Subject: [PATCH 14/63] test for not given an array --- Sprint-1/implement/max.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 0c4908788..71fb7bc16 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -40,6 +40,10 @@ test("throws for an array containing a non-number", () => { expect(() => findMax(["hey", 10])).toThrow(new Error("findMax requires an array of numbers")); }); +test("throws when not given an array", () => { + expect(() => findMax("hey")).toThrow(new Error("findMax requires an array of numbers")); +}); + From f095dbf006456857273d16da5f997c3ad0c264fb Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:36:55 +0100 Subject: [PATCH 15/63] fix not array test --- Sprint-1/implement/max.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..83bc1531a 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,8 @@ function findMax(elements) { + if(!Array.isArray(elements)) { + throw new Error("findMax requires an array of numbers"); + }; + } module.exports = findMax; From 3660134585f0f8e339d99eeca55ac751a59a9ae4 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:38:58 +0100 Subject: [PATCH 16/63] length equals zero test fix --- 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 83bc1531a..50d391133 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -2,6 +2,11 @@ function findMax(elements) { if(!Array.isArray(elements)) { throw new Error("findMax requires an array of numbers"); }; + + if (elements.length === 0) { + return -infinity; + }; + } From 289a04c9fbbd5ba2b1163974566d1e87120e18f0 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:41:59 +0100 Subject: [PATCH 17/63] refactor error handling and formatting in findMax function --- Sprint-1/implement/max.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 50d391133..2f30872d4 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,13 +1,15 @@ function findMax(elements) { - if(!Array.isArray(elements)) { - throw new Error("findMax requires an array of numbers"); - }; + if (!Array.isArray(elements)) { + throw new Error("findMax requires an array of numbers"); + } - if (elements.length === 0) { - return -infinity; - }; + if (elements.length === 0) { + return -infinity; + } - + if (!element.every((item) => typeof item === "numbers")) { + throw new Error("findMax requires an array of numbers"); + } } module.exports = findMax; From d70f1766ee29fd4cc4ef023fcfa49d10e5524939 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:54:11 +0100 Subject: [PATCH 18/63] fix: correct case of -Infinity in empty array test --- Sprint-1/implement/max.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 71fb7bc16..d1de857f0 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -17,7 +17,7 @@ const findMax = require("./max.js"); // Then it should return -Infinity // Delete this test.todo and replace it with a test. test("given an empty array, returns -Infinity", () => { - expect(findMax([])).toBe(-infinity); + expect(findMax([])).toBe(-Infinity); }); test("given an array with one number, returns that number", () => { From 2163cf1b0d9910c60493146e1f483c9babcaf4db Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sat, 24 Oct 2026 23:54:16 +0100 Subject: [PATCH 19/63] fix: correct case of -Infinity and fix type checks in findMax function --- Sprint-1/implement/max.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 2f30872d4..2d1147c06 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -4,12 +4,20 @@ function findMax(elements) { } if (elements.length === 0) { - return -infinity; + return -Infinity; } - if (!element.every((item) => typeof item === "numbers")) { + if (!elements.every((item) => typeof item === "number")) { throw new Error("findMax requires an array of numbers"); } + + let max = elements[0]; + for (const item of elements) { + if (item > max) { + max = item; + } + } + return max; } module.exports = findMax; From 0eb22a90e8090d0a7c3a93cbdff96a828bf54970 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 11:50:26 +0000 Subject: [PATCH 20/63] refactor: remove unnecessary comments and clean up max.test.js --- Sprint-1/implement/max.test.js | 41 ---------------------------------- 1 file changed, 41 deletions(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index d1de857f0..655a0e4d2 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -1,21 +1,3 @@ -/* Find the maximum element of an array of numbers - -In this kata, you will need to implement a function that find the largest numerical element of an array. - -E.g. max([30, 50, 10, 40]), target output: 50 -E.g. max(['hey', 10, 'hi', 60, 10]) throws Error("findMax requires an array of numbers") (max can't compare non-numerical elements, so it shouldn't guess) - -You should implement this function in max.js, and add tests for it in this file. - -We have set things up already so that this file can see your function from the other file. -*/ - -const findMax = require("./max.js"); - -// Given an empty array -// When passed to the max function -// Then it should return -Infinity -// Delete this test.todo and replace it with a test. test("given an empty array, returns -Infinity", () => { expect(findMax([])).toBe(-Infinity); }); @@ -51,26 +33,3 @@ test("throws when not given an array", () => { -// Given an array with one number -// When passed to the max function -// Then it should return 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 - -// Given an array with just negative numbers -// When passed to the max function -// Then it should return the closest one to zero - -// Given an array with decimal numbers -// When passed to the max function -// Then it should return the largest decimal 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") - -// 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 794f3b1d5f1b99ef9397be4ab560f5785faf447f Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 11:50:43 +0000 Subject: [PATCH 21/63] refactor: improve formatting and indentation in max.test.js --- Sprint-1/implement/max.test.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 655a0e4d2..9d140d41f 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -11,25 +11,21 @@ test("returns the largest of positive and negative numbers", () => { }); test("returns the closest to zero for all negatives", () => { - expect(findMax([-9, -2, -6])).toBe(-2); + expect(findMax([-9, -2, -6])).toBe(-2); }); test("returns the largest decimal number", () => { - expect(findMax([1.2, 3.8, 2.6])).toBe(3.8); + expect(findMax([1.2, 3.8, 2.6])).toBe(3.8); }); test("throws for an array containing a non-number", () => { - expect(() => findMax(["hey", 10])).toThrow(new Error("findMax requires an array of numbers")); + expect(() => findMax(["hey", 10])).toThrow( + new Error("findMax requires an array of numbers") + ); }); test("throws when not given an array", () => { - expect(() => findMax("hey")).toThrow(new Error("findMax requires an array of numbers")); + expect(() => findMax("hey")).toThrow( + new Error("findMax requires an array of numbers") + ); }); - - - - - - - - From 8dc93cee5089e73e70395329f4dc3656db8a815f Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 11:56:37 +0000 Subject: [PATCH 22/63] test: implement test case for empty array in sum function --- Sprint-1/implement/sum.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index a288e0f0a..10e1478ab 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -13,7 +13,10 @@ 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 87581d494a71cc0d7bca3b98cfa6413ca43518b4 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 11:58:45 +0000 Subject: [PATCH 23/63] test: fix test case for returning a number from an array --- 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 10e1478ab..ef2007c61 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -17,6 +17,9 @@ test("given an empty array, returns 0", () => { expect(sum[]).toBe(0); }); +test("given an array with one number, return that number", () => { + expect(sun[8]).toBe(8); +}); // Given an array with just one number // When passed to the sum function From 6fb4efd15965efb80792a25eaf3592f6c606de67 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:00:44 +0000 Subject: [PATCH 24/63] test: fix test case for adding negative 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 ef2007c61..96d146ded 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -21,6 +21,10 @@ test("given an array with one number, return that number", () => { expect(sun[8]).toBe(8); }); +test("adds negative number correctly", () => { + expect(sum[-5, 3, -10]).toBe(12); +}); + // Given an array with just one number // When passed to the sum function // Then it should return that number From cf804504fb47c09cf20a2ec498582fa8564853d7 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:05:01 +0000 Subject: [PATCH 25/63] test: add test cases for decimal numbers and non-number inputs in sum function --- Sprint-1/implement/sum.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index 96d146ded..336a2afa1 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -25,6 +25,14 @@ test("adds negative number correctly", () => { expect(sum[-5, 3, -10]).toBe(12); }); +test("adds decimal numbers correctly", () => { + expect(sum[1.5, 2.25, 3]).toBe(6.75); +}); + +test("throws for an array containing a non-number", () => { + expect(() => sum(["hey", 10])).toThrow("sum requires an array of numbers"); +}); + // Given an array with just one number // When passed to the sum function // Then it should return that number From 04f33f83ebcd306abe8d3f05c8f721b95bd5ed21 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:08:17 +0000 Subject: [PATCH 26/63] test: add case to throw error when input is not an array 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 336a2afa1..1d316771a 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -33,6 +33,10 @@ test("throws for an array containing a non-number", () => { expect(() => sum(["hey", 10])).toThrow("sum requires an array of numbers"); }); +test("throws when not given an array", () =>{ + expect(() => sum("hey")).toThrow(new Error("sum requires an array of numbers")); +}); + // Given an array with just one number // When passed to the sum function // Then it should return that number From 14a6f66631a08d11bd703cc7e9570e106472da87 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:10:06 +0000 Subject: [PATCH 27/63] fix: correct variable name in array check for 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..d47ad8262 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,7 @@ function sum(elements) { + if (!Array.isArray(list)) { + throw new Error("sum requires an array of numbers"); + } } module.exports = sum; From 20c90a27bdfb0ebbad1fe569a8ea76ba2262bd84 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:12:35 +0000 Subject: [PATCH 28/63] fix: correct variable name in array check for 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 d47ad8262..3333b0879 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -2,6 +2,9 @@ function sum(elements) { if (!Array.isArray(list)) { throw new Error("sum requires an array of numbers"); } + if (!list.every((item) => typeof item === "number")) { + throw new Error("sum requires an array of numbers"); + } } module.exports = sum; From 021392c230793b6881918b2f167e60355f5f5c48 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:14:08 +0000 Subject: [PATCH 29/63] fix: correct variable name and implement summation logic in sum function --- Sprint-1/implement/sum.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 3333b0879..99db9aadd 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -5,6 +5,11 @@ function sum(elements) { if (!list.every((item) => typeof item === "number")) { throw new Error("sum requires an array of numbers"); } + let total = 0; + for(const item of list) { + total += item; + } + return total } module.exports = sum; From bca87982b4193311f25321c1aa70594fac160f5f Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:14:24 +0000 Subject: [PATCH 30/63] fix: correct formatting in sum function for consistency --- Sprint-1/implement/sum.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 99db9aadd..64b517e6d 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -6,10 +6,10 @@ function sum(elements) { throw new Error("sum requires an array of numbers"); } let total = 0; - for(const item of list) { + for (const item of list) { total += item; } - return total + return total; } module.exports = sum; From 9c02fb8466d96ace29cd4ba1123dd8b0adf7ee7b Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:15:54 +0000 Subject: [PATCH 31/63] fix: correct syntax errors in sum function tests --- Sprint-1/implement/sum.test.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index 1d316771a..f709dc2b9 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -14,27 +14,29 @@ const sum = require("./sum.js"); // When passed to the sum function // Then it should return 0 test("given an empty array, returns 0", () => { - expect(sum[]).toBe(0); + expect(sum([])).toBe(0); }); test("given an array with one number, return that number", () => { - expect(sun[8]).toBe(8); + expect(sun[8]).toBe(8); }); test("adds negative number correctly", () => { - expect(sum[-5, 3, -10]).toBe(12); + expect(sum[(-5, 3, -10)]).toBe(12); }); test("adds decimal numbers correctly", () => { - expect(sum[1.5, 2.25, 3]).toBe(6.75); + expect(sum[(1.5, 2.25, 3)]).toBe(6.75); }); test("throws for an array containing a non-number", () => { - expect(() => sum(["hey", 10])).toThrow("sum requires an array of numbers"); + expect(() => sum(["hey", 10])).toThrow("sum requires an array of numbers"); }); -test("throws when not given an array", () =>{ - expect(() => sum("hey")).toThrow(new Error("sum requires an array of numbers")); +test("throws when not given an array", () => { + expect(() => sum("hey")).toThrow( + new Error("sum requires an array of numbers") + ); }); // Given an array with just one number From 718a3b13c08bf5781c31e9102dc6ec95379a263b Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:27:54 +0000 Subject: [PATCH 32/63] fix: correct function calls in sum tests for accuracy --- Sprint-1/implement/sum.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index f709dc2b9..8c0e1353a 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -18,15 +18,15 @@ test("given an empty array, returns 0", () => { }); test("given an array with one number, return that number", () => { - expect(sun[8]).toBe(8); + expect(sum([8])).toBe(8); }); test("adds negative number correctly", () => { - expect(sum[(-5, 3, -10)]).toBe(12); + expect(sum([-5, 3, -10])).toBe(-12); }); test("adds decimal numbers correctly", () => { - expect(sum[(1.5, 2.25, 3)]).toBe(6.75); + expect(sum([1.5, 2.25, 3])).toBe(6.75); }); test("throws for an array containing a non-number", () => { From 75a3863565aee910597bee6808e3667fcde20e72 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:28:00 +0000 Subject: [PATCH 33/63] fix: rename parameter in sum function for clarity --- Sprint-1/implement/sum.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 64b517e6d..6b578d356 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,4 @@ -function sum(elements) { +function sum(list) { if (!Array.isArray(list)) { throw new Error("sum requires an array of numbers"); } From c555e307dcd31553c615e1fbf5cdaece46168f5d Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:28:07 +0000 Subject: [PATCH 34/63] fix: add missing import statement for findMax in max tests --- Sprint-1/implement/max.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 9d140d41f..61090ad8c 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -1,3 +1,5 @@ +const findMax = require("./max.js"); + test("given an empty array, returns -Infinity", () => { expect(findMax([])).toBe(-Infinity); }); From 0a8ffc994de0706aecc4a5e65ead40916f13acbf Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:29:25 +0000 Subject: [PATCH 35/63] fix: remove unnecessary comments and documentation in sum tests for clarity --- Sprint-1/implement/sum.test.js | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index 8c0e1353a..55a2135ec 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -1,18 +1,5 @@ -/* Sum the numbers in an array - -In this kata, you will need to implement a function that sums the numerical elements of an array - -E.g. sum([10, 20, 30]), target output: 60 -E.g. sum(['hey', 10, 'hi', 60, 10]) throws Error("sum requires an array of numbers") (sum can't add non-numerical elements, so it shouldn't guess) -*/ - const sum = require("./sum.js"); -// Acceptance Criteria: - -// Given an empty array -// When passed to the sum function -// Then it should return 0 test("given an empty array, returns 0", () => { expect(sum([])).toBe(0); }); @@ -38,23 +25,3 @@ test("throws when not given an array", () => { new Error("sum requires an array of numbers") ); }); - -// Given an array with just one number -// When passed to the sum function -// Then it should return that number - -// Given an array containing negative numbers -// When passed to the sum function -// Then it should still return the correct total sum - -// Given an array with decimal/float numbers -// When passed to the sum function -// Then it should return the correct total 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") - -// 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 7d531a40166a9f7ccaadcb093f8646035e7c848f Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:33:12 +0000 Subject: [PATCH 36/63] fix: implement test for empty array case in dedupe function --- Sprint-1/implement/dedupe.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index d7c8e3d8e..3ffda3a18 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 @@ -24,5 +26,5 @@ test.todo("given an empty array, it returns an empty array"); // Given an array of strings or numbers // When passed to the dedupe function -// Then it should return a new array with duplicates removed while preserving the +// Then it should return a new array with duplicates removed while preserving the // first occurrence of each element from the original array. From c9a0b25cb0a40800dec7b123ec7e843c37c66fd2 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:36:23 +0000 Subject: [PATCH 37/63] fix: add test for dedupe function to verify handling of duplicate elements --- Sprint-1/implement/dedupe.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 3ffda3a18..e733b90de 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -20,6 +20,10 @@ test("given an empty array, it returns an empty array", () => { expect(dedupe([])).toEqual([]); }); +test("returns a a copy with no duplicates", () => { + expect(dedupe(["a", "a", "a", "b", "b", "c"])).toEqual(["a", "b", "c"]); +}); + // Given an array with no duplicates // When passed to the dedupe function // Then it should return a copy of the original array From b21e5319a56cfff112b7f933a72ca7a67ca656d9 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:39:14 +0000 Subject: [PATCH 38/63] fix: add test to verify preservation of first occurrence order in dedupe function --- 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 e733b90de..2a4e5431a 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -24,6 +24,11 @@ test("returns a a copy with no duplicates", () => { expect(dedupe(["a", "a", "a", "b", "b", "c"])).toEqual(["a", "b", "c"]); }); +test("keeps the first occurrence order", () => { + expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]); +}); + + // Given an array with no duplicates // When passed to the dedupe function // Then it should return a copy of the original array From 586f2b0c8cc791a3f68fa54869ada361d10c9fff Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:45:53 +0000 Subject: [PATCH 39/63] feat: implement dedupe function to remove duplicates from an array --- Sprint-1/implement/dedupe.js | 12 +++++++++++- Sprint-1/implement/dedupe.test.js | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..b54117bd9 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,11 @@ -function dedupe() {} +function dedupe(list) { + const result = []; + for (const item of list) { + if (!result.includes(item)) { + result.push(item); + } + } + return result; +} + +module.exports = dedupe; diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 2a4e5431a..ffc5403cf 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -28,7 +28,6 @@ test("keeps the first occurrence order", () => { expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]); }); - // Given an array with no duplicates // When passed to the dedupe function // Then it should return a copy of the original array From 9fe1206030cc465776734e7de57e6c988b3fb613 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:46:27 +0000 Subject: [PATCH 40/63] fix: remove unnecessary comments and documentation in dedupe tests for clarity --- Sprint-1/implement/dedupe.test.js | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index ffc5403cf..b20e1f851 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -1,21 +1,5 @@ const dedupe = require("./dedupe.js"); -/* -Dedupe Array -📖 Dedupe means **deduplicate** - -In this kata, you will need to deduplicate the elements of an array - -E.g. dedupe(['a','a','a','b','b','c']) returns ['a','b','c'] -E.g. dedupe([5, 1, 1, 2, 3, 2, 5, 8]) returns [5, 1, 2, 3, 8] -E.g. dedupe([1, 2, 1]) returns [1, 2] -*/ - -// Acceptance Criteria: - -// Given an empty array -// When passed to the dedupe function -// Then it should return an empty array test("given an empty array, it returns an empty array", () => { expect(dedupe([])).toEqual([]); }); @@ -27,12 +11,3 @@ test("returns a a copy with no duplicates", () => { test("keeps the first occurrence order", () => { expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]); }); - -// Given an array with no duplicates -// When passed to the dedupe function -// Then it should return a copy of the original array - -// Given an array of strings or numbers -// 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. From 9d715a4c7adecf62cb12c9cc81bbee392f031695 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:49:30 +0000 Subject: [PATCH 41/63] test: implement test for calculateMean function with sample input --- 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..26b67351d 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 [1, 2, 6], returns 3", () => { + expect(calculateMean([8])).toBe(8); +}); // Given an array with a single number // When passed to calculateMean From 320a5fa60b6d2e6f8964ed944b817027efc04de9 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:51:50 +0000 Subject: [PATCH 42/63] test: update calculateMean test case to return correct mean for multiple numbers --- 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 26b67351d..00c9d6556 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -24,9 +24,13 @@ const calculateMean = require("./mean.js"); // Then it should return their mean // Delete this test.todo and replace it with a test. test("given [1, 2, 6], returns 3", () => { - expect(calculateMean([8])).toBe(8); + expect(calculateMean([1, 2, 6])).toBe(3); }); +test("returns the number for a single item array", () => { + expect(calculateMean) +}) + // Given an array with a single number // When passed to calculateMean // Then it should return that number From d3d915660346e87c0cc5fd14eaa7c908fdd864f8 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:52:33 +0000 Subject: [PATCH 43/63] test: add case to verify calculateMean returns correct value for single item array --- Sprint-1/implement/mean.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 00c9d6556..0b3117455 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -28,8 +28,8 @@ test("given [1, 2, 6], returns 3", () => { }); test("returns the number for a single item array", () => { - expect(calculateMean) -}) + expect(calculateMean([8])).toBe(8); +}); // Given an array with a single number // When passed to calculateMean From 7f9881d8f55a8e99caaa2a182314e906e142eb21 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:55:12 +0000 Subject: [PATCH 44/63] test: add case to verify calculateMean handles negative and decimal numbers --- 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 0b3117455..9c32e483d 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -31,6 +31,11 @@ test("returns the number for a single item array", () => { expect(calculateMean([8])).toBe(8); }); +test("handles negative and decimal numbers", () => { + expects(calculateMean([-2, 4, 3.5])).toBeCloseTo(1.8333); +}); + +test // Given an array with a single number // When passed to calculateMean // Then it should return that number From 9ea6b81c0fbd9c5c28469b7eba17f17f5dffd587 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 12:58:10 +0000 Subject: [PATCH 45/63] test: add case to verify calculateMean throws error for empty 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 9c32e483d..b3cf6ba99 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -35,7 +35,11 @@ test("handles negative and decimal numbers", () => { expects(calculateMean([-2, 4, 3.5])).toBeCloseTo(1.8333); }); -test +test("throws for an empty array", () => { + expect(() => calculateMean([])).toThrow( + new Error("calculateMean requires a non-empty array") + ); +}); // Given an array with a single number // When passed to calculateMean // Then it should return that number From 58bc16ca41dee03dfab63ec391e26c539e8cab65 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 13:04:48 +0000 Subject: [PATCH 46/63] test: add cases to verify calculateMean throws errors for invalid inputs --- 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 b3cf6ba99..872f2c4fd 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -40,6 +40,18 @@ test("throws for an empty array", () => { new Error("calculateMean requires a non-empty array") ); }); + +test("throws when not given an array", () => { + expect(() => calculateMean("banana")).toThrow( + new Error("calculateMean requires an array of numbers") + ); +}); + +test("throws for an array containing. a non-number", () => { + expect(() => calculateMean([1, "2", 3])).toThrow( + new Error("calculateMean requires a array of numbers") + ); +}); // Given an array with a single number // When passed to calculateMean // Then it should return that number From 44859cb35884fa679b1b9591780c3b4a22f3fb81 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 13:05:39 +0000 Subject: [PATCH 47/63] test: remove unnecessary comments and documentation from mean test file --- Sprint-1/implement/mean.test.js | 46 --------------------------------- 1 file changed, 46 deletions(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 872f2c4fd..aedb2aeb9 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -1,28 +1,5 @@ -/* Calculate the mean of an array of numbers - -In this kata, you will need to implement a function that calculates the mean of an array of numbers. - -E.g. calculateMean([1, 2, 6]), target output: 3 -E.g. calculateMean([]) throws Error("calculateMean requires a non-empty array") -E.g. calculateMean("banana") throws Error("calculateMean requires an array of numbers") - -There is no mean of an empty array, and a string isn't an array of numbers, so -calculateMean should throw rather than return a value. This is the same problem -calculateMedian solves in the prep and in the fix directory. - -You should implement this function in mean.js, and add tests for it in this file. - -We have set things up already so that this file can see your function from the other file. -*/ - const calculateMean = require("./mean.js"); -// Acceptance criteria: - -// 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("given [1, 2, 6], returns 3", () => { expect(calculateMean([1, 2, 6])).toBe(3); }); @@ -52,26 +29,3 @@ test("throws for an array containing. a non-number", () => { new Error("calculateMean requires a array of numbers") ); }); -// Given an array with a single number -// When passed to calculateMean -// Then it should return that number - -// Given an array containing negative or decimal numbers -// When passed to calculateMean -// Then it should return the correct mean - -// 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") - -// 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 c15204d52d250cc7e4077f50d621c9fad973c92d Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 13:07:19 +0000 Subject: [PATCH 48/63] test: implement input validation for calculateMean function --- Sprint-1/implement/mean.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index 36909ea1f..703abf0b9 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -1,3 +1,7 @@ -function calculateMean(list) {} +function calculateMean(list) { + if (!Array.isArray(list)) { + throw new Error("calculateMean requires an array of numbers"); + } +} module.exports = calculateMean; From e94100ef293aceefc186bb8f7a39e2dbe78f32b6 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 13:09:17 +0000 Subject: [PATCH 49/63] test: add validation for non-empty array 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 703abf0b9..3ce0b2933 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -2,6 +2,9 @@ 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"); + } } module.exports = calculateMean; From e912e066af3db40af02acd0fbc24696e1eb33db1 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 13:13:30 +0000 Subject: [PATCH 50/63] fix: ensure calculateMean validates input as an array of numbers --- Sprint-1/implement/mean.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index 3ce0b2933..340508a03 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -5,6 +5,14 @@ function calculateMean(list) { if (list.length === 0) { throw new Error("calculateMean requires a non-empty array"); } + if (!list.every((item) => typeof item === "number")) { + throw new Error("calculateMean requires an array of numbers"); + } + let total = 0; + for (const item of list) { + total += item; + } + return total / list.length; } module.exports = calculateMean; From ab6b5a46aa1fe2706008ee35c7a7fb2767d0ed12 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 13:15:29 +0000 Subject: [PATCH 51/63] fix: correct error message and test description for non-number array validation --- Sprint-1/implement/mean.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index aedb2aeb9..3fe807300 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -24,8 +24,8 @@ test("throws when not given an array", () => { ); }); -test("throws for an array containing. a non-number", () => { +test("throws for an array containing a non-number", () => { expect(() => calculateMean([1, "2", 3])).toThrow( - new Error("calculateMean requires a array of numbers") + new Error("calculateMean requires an array of numbers") ); }); From 88a8db1a3b557aa5f0801aa7485e1400ae08c3a7 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Sun, 25 Oct 2026 13:16:27 +0000 Subject: [PATCH 52/63] fix: correct typo in test for handling negative and decimal numbers --- Sprint-1/implement/mean.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 3fe807300..d4a592e2d 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -9,7 +9,7 @@ test("returns the number for a single item array", () => { }); test("handles negative and decimal numbers", () => { - expects(calculateMean([-2, 4, 3.5])).toBeCloseTo(1.8333); + expect(calculateMean([-2, 4, 3.5])).toBeCloseTo(1.8333); }); test("throws for an empty array", () => { From da1d6fdfdf6a4ec70667e442afe177ae21cf61c5 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Mon, 26 Oct 2026 16:14:15 +0000 Subject: [PATCH 53/63] test: implement test for describeMedian function with valid input --- Sprint-1/implement/describe-median.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index e7d18a264..86e88019f 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -21,7 +21,11 @@ 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("Tne median is 2"); +}); + + // Given an empty array // When passed to describeMedian From edf099cf92e09ccb9e16f3524da6f8c16f3a1bf5 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Mon, 26 Oct 2026 16:14:33 +0000 Subject: [PATCH 54/63] test: fix expected output for describeMedian function with valid input --- Sprint-1/implement/describe-median.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index 86e88019f..2a96ddd9f 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -25,6 +25,13 @@ test('given [1, 2, 3], returns "The median is 2"', () => { expect(describeMedian([1, 2, 3])).toBe("Tne median is 2"); }); +test("returns a sentence for an empty array", () => { + expect(describeMedian([])).toBe( + "Could not calculate median: calculateMedian requires a non-empty array" + ); +}); + + // Given an empty array From 2d2960d93d7780787961cc3f0de0e8ac2f9207a2 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Mon, 26 Oct 2026 16:18:16 +0000 Subject: [PATCH 55/63] test: add missing test for non-array input in describeMedian function --- Sprint-1/implement/describe-median.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index 2a96ddd9f..c1239ccab 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -31,8 +31,11 @@ test("returns a sentence for an empty array", () => { ); }); - - +test("return a sentence for a non-array", () => { + expect(describeMedian("banana")).toBe( + "Could not calculate median: calculateMedian requires an array of numbers" + ); +}); // Given an empty array // When passed to describeMedian From 34a81961fb31cb178752a9b6e7dc4f79c63caf14 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Mon, 26 Oct 2026 16:26:06 +0000 Subject: [PATCH 56/63] fix: correct error messages in tests for describeMedian function --- Sprint-1/implement/describe-median.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index c1239ccab..f185d42b5 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -27,13 +27,13 @@ test('given [1, 2, 3], returns "The median is 2"', () => { test("returns a sentence for an empty array", () => { expect(describeMedian([])).toBe( - "Could not calculate median: calculateMedian requires a non-empty array" + "Could not calculate a median: calculateMedian requires a non-empty array" ); }); test("return a sentence for a non-array", () => { expect(describeMedian("banana")).toBe( - "Could not calculate median: calculateMedian requires an array of numbers" + "Could not calculate a median: calculateMedian requires an array of numbers" ); }); From c60bbdf93459c009dab76a52f5bc120c484ae5cd Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Mon, 26 Oct 2026 16:26:12 +0000 Subject: [PATCH 57/63] feat: implement describeMedian function to calculate and return the median --- Sprint-1/implement/describe-median.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/describe-median.js b/Sprint-1/implement/describe-median.js index 3381cfc0a..e6a0a4033 100644 --- a/Sprint-1/implement/describe-median.js +++ b/Sprint-1/implement/describe-median.js @@ -20,6 +20,13 @@ function calculateMedian(list) { } // Implement this function. See describe-median.test.js for the acceptance criteria. -function describeMedian(list) {} +function describeMedian(list) { + try { + const median = calculateMedian(list); + return "The median is " + median; + } catch (error) { + return "Could not calculate a median: " + error.message; + } +} module.exports = describeMedian; From 783f7e66edf5b4d4e2f908e3a043043b11634dbe Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Mon, 26 Oct 2026 16:27:59 +0000 Subject: [PATCH 58/63] fix: correct median test output and remove unnecessary comments --- Sprint-1/implement/describe-median.test.js | 30 +--------------------- prep/doubleAllNumbers.js | 13 ++++++++++ 2 files changed, 14 insertions(+), 29 deletions(-) create mode 100644 prep/doubleAllNumbers.js diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index f185d42b5..711d96791 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -1,28 +1,8 @@ -/* Describe the median, or explain why there isn't one - -calculateMedian is given to you at the top of describe-median.js. It throws -when it can't calculate a median. Don't change it. - -Implement describeMedian, which calls calculateMedian and returns a sentence -instead of crashing. - -E.g. describeMedian([1, 2, 3]), target output: "The median is 2" -E.g. describeMedian([]), target output: "Could not calculate a median: calculateMedian requires a non-empty array" - -You'll need a try/catch block for this. The catch block must use the error's -message, so the caller can see what went wrong. -*/ - const describeMedian = require("./describe-median.js"); -// Acceptance criteria: -// Given an array of numbers -// 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('given [1, 2, 3], returns "The median is 2"', () => { - expect(describeMedian([1, 2, 3])).toBe("Tne median is 2"); + expect(describeMedian([1, 2, 3])).toBe("The median is 2"); }); test("returns a sentence for an empty array", () => { @@ -36,11 +16,3 @@ test("return a sentence for a non-array", () => { "Could not calculate a median: calculateMedian requires an array of numbers" ); }); - -// Given an empty array -// When passed to describeMedian -// Then it should return "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" diff --git a/prep/doubleAllNumbers.js b/prep/doubleAllNumbers.js new file mode 100644 index 000000000..58045564e --- /dev/null +++ b/prep/doubleAllNumbers.js @@ -0,0 +1,13 @@ +function doubleAllNumbers() { + let doubledNumbers; + + for (let n of numbers) { + doubledNumbers.push(n * 2); + } + + return doubledNumbers; +} + +const myNums = [10, 20, 30]; +doubleAllNumbers(myNums); +console.log(myNums); From 611dd7fded3d6b7c5c7b1035ac43aa4af4df15a0 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Mon, 26 Oct 2026 20:46:47 +0000 Subject: [PATCH 59/63] refactor: simplify includes function using for...of loop --- 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 9a34fb937008aa5302421aaeecf2def77f47aaa1 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 27 Oct 2026 16:33:40 +0000 Subject: [PATCH 60/63] fix: update input values in aoc-2018-day1 dataset for accuracy --- Sprint-1/stretch/aoc-2018-day1/input.txt | 1502 ++++++++++++---------- 1 file changed, 794 insertions(+), 708 deletions(-) diff --git a/Sprint-1/stretch/aoc-2018-day1/input.txt b/Sprint-1/stretch/aoc-2018-day1/input.txt index 1ffa65fc8..67857469c 100644 --- a/Sprint-1/stretch/aoc-2018-day1/input.txt +++ b/Sprint-1/stretch/aoc-2018-day1/input.txt @@ -1,951 +1,1037 @@ --10 --12 -+1 -+14 -+11 --19 --4 -+10 -+10 --12 --13 --10 --8 ++13 ++19 +11 -+3 --10 -+8 -+5 --14 ++15 ++1 +7 -+12 -+12 ++17 +14 --1 +-16 ++15 ++4 +-2 +-10 ++2 +17 ++18 -5 -+9 --15 -+8 +-18 +-18 -16 -+9 -+6 -+17 -11 -+19 -+11 +-9 -9 -1 --8 --16 --5 -+6 -+2 +6 +12 -+15 -+16 --6 --8 --5 ++14 ++3 ++7 +11 ++13 ++10 -9 -+19 -+19 --5 --12 --17 --20 -+9 --6 --2 -+20 -+15 --8 ++16 +15 -+19 --5 ++18 +-19 -17 --9 +1 --9 --11 --19 --1 --15 -+18 --4 +-7 ++11 +19 -+3 -+21 -+5 --1 -+8 -+9 -+9 --16 -+17 --15 -+18 -+14 -+8 --13 -2 --15 -+13 +-3 +19 --13 -+5 ++12 ++9 ++7 +16 ++1 ++5 +-11 +-7 +16 -+7 -+8 --19 +3 --12 -+18 --16 --19 ++12 +8 --16 -+20 -+15 --5 -17 -+15 -+14 --2 -+18 --6 -+5 -+16 -+13 -8 +-11 ++5 -9 --1 -+13 -+18 --2 -+16 --4 -+19 -+6 -+14 --6 --16 --10 --5 --15 -+11 +-18 +10 -+18 -+8 --2 -+15 --9 -+7 +-7 ++2 ++4 ++4 +10 -+9 --6 ++13 ++6 +1 --17 --12 -+19 +-19 ++16 +14 -9 --18 -+20 -+12 -+10 -+14 -+6 -+9 --18 -+4 +15 ++19 +-18 +15 +-10 +-7 ++16 +3 -+9 --4 --19 ++19 +-17 +8 -+16 +19 --12 --1 -+16 -+11 ++14 +-17 +-15 +-18 +-16 +13 --8 +-16 ++13 ++17 ++17 ++6 ++7 ++8 +-11 +-17 +4 -+18 +-12 +-17 ++20 ++19 ++8 +10 --11 ++9 ++21 ++17 ++12 +18 --8 -+19 --4 --5 --12 --3 --10 --11 --18 -7 ++19 +-8 +-19 +3 -+14 -+18 -+2 -7 --12 -+14 -+12 -+13 --1 -+13 --1 -+15 -+13 --1 --17 --4 -+17 +-2 -3 ++16 +13 -+5 +-16 +-16 -19 -+17 +10 -+6 --15 -+11 -+16 -+11 -+20 +-19 ++14 +-9 +-17 ++7 ++1 ++2 +19 -+5 --11 --2 --12 --6 --11 ++7 +-14 ++1 +-8 ++3 -14 -+5 -+10 --23 -+14 -11 -+22 --1 ++2 ++19 ++19 +-20 +-8 -14 --35 --23 -+11 -+4 +10 --6 ++2 ++16 ++15 ++8 +19 --5 -+4 +-14 ++16 +-10 ++1 ++14 ++18 -13 --7 -+11 --24 --17 -+9 --17 -+11 -+2 -4 --10 --24 ++12 ++8 +-1 +-18 ++5 ++1 +14 -+15 ++7 ++6 +19 +-16 ++19 ++13 ++5 ++10 +-12 +7 --2 -+11 --13 --8 --8 --14 ++7 ++20 ++12 -17 -+6 -+8 ++13 ++18 +-13 +-9 ++12 ++5 +-10 ++3 ++5 ++16 +-7 +-1 ++11 ++12 -16 ++7 ++13 ++9 -18 -+1 --21 --14 -+8 --2 -+20 --19 +-9 ++4 +-20 +9 --15 --6 --7 ++8 ++6 +4 --3 ++11 ++7 -8 -+16 -+15 --26 -+18 --22 --16 +-13 +-2 ++17 +-7 -3 --17 --18 -+4 ++11 ++12 ++3 +-7 ++5 +5 +3 --1 ++5 +3 -+2 +-10 ++11 +-8 +-5 +3 -+7 ++19 -5 -+20 --11 -+15 --6 --19 --24 ++4 ++10 -6 --20 -+13 --4 ++12 +-11 ++3 ++9 ++10 -18 +-19 ++7 +-11 +-8 +-12 +-9 +-7 +-17 +15 -+9 -+16 -+12 --5 +-16 +-13 +-10 +-8 +16 -+9 --4 ++18 +-10 ++1 -14 -9 +-14 ++11 -19 +-2 +-18 -5 --16 --16 -+5 --4 +-19 ++17 ++8 +12 ++12 ++6 -15 --15 --14 -+4 --18 --12 --4 +-1 ++2 ++20 +-8 +6 +-13 ++1 +9 --12 -+14 -+9 --6 -+3 -+8 -+4 -+7 --14 --15 --18 -+12 ++18 ++16 -19 --14 --15 --16 -+15 +-17 +-24 +-1 -8 -+14 --4 --21 -+7 -12 --2 --10 +-17 -6 -+14 -+14 --9 --14 -16 -+2 -+7 ++13 +-10 ++17 ++13 ++8 +-17 +5 +-11 ++9 ++19 ++18 ++17 -15 ++14 -15 -+19 --16 --5 --16 --19 -+9 --27 --8 +-17 +-17 ++19 +6 -+1 --14 --9 --50 +-13 -9 --21 -+5 ++1 -20 --19 -+6 --11 -+6 +-1 +-7 +-3 +1 ++14 -17 +-16 +-16 +-18 +-7 +-19 -14 --2 +-18 +8 --4 -+16 ++14 +1 --3 +-12 -9 -+20 ++13 ++9 +-10 ++6 +15 --22 ++19 ++11 +-9 -3 --13 --12 --25 -+5 --13 --2 --8 --11 -+17 ++8 +3 --7 -+13 -+1 -+18 --13 ++6 +1 -+7 --15 --43 --6 --10 --9 --20 ++6 +-27 ++17 ++24 -7 ++20 ++23 ++16 ++3 -8 --15 --9 -+13 ++20 ++10 +-5 +-4 -9 -+24 -+13 -+5 -8 +-11 +-31 +-10 ++13 -15 --4 --4 --4 --14 --21 -+16 -+15 --14 --20 --20 --15 --19 --41 ++29 ++1 +16 -+3 -+8 --22 --30 -+8 ++10 +40 -+15 -+24 --7 -+22 ++9 +10 -+15 ++3 ++13 ++4 ++10 ++29 ++6 +-11 +-5 ++32 +-14 ++5 ++13 +-17 +-8 +9 -+28 -+14 ++29 ++17 ++3 +2 ++13 +-19 +14 ++10 ++2 ++5 +-15 +-19 +-20 ++12 ++19 ++24 +6 -+17 +-23 ++14 +-18 +1 -+30 -+5 ++10 +-20 ++34 ++9 -2 -+46 -+24 -+46 --3 ++18 ++15 -7 -+35 ++19 +-13 ++7 ++16 ++12 +-11 +-15 +-6 ++19 +16 ++9 ++5 +13 --21 -+28 ++17 +13 --25 -+180 -+25 +-1 +-1 +-16 +-18 ++16 +5 --9 -+23 --5 --2 -+13 --12 ++21 +2 --25 --5 -+18 --24 -+45 -+17 --7 ++2 ++9 +-14 +22 --152 --11 -+4 -+50 -+129 --7 ++12 +-2 +-6 +22 -+109 --56 -+80 -+29 --75060 -2 --14 -+7 -17 --5 -+6 --3 -+18 -+19 ++2 +-14 +-9 ++16 ++25 +-7 ++34 ++5 -14 +-34 ++11 +-28 -12 --6 -+9 +-16 +-18 ++17 +-9 ++6 -5 +-19 +-17 +-16 ++2 +-8 ++11 -13 --6 --3 --15 -+13 -+3 --18 --11 -+16 --2 +-4 +10 -14 +-19 +-14 -7 -+19 --20 -+15 -+10 -+12 ++2 ++2 ++4 ++5 ++30 +-19 +10 -+16 --11 +-17 ++2 +-25 ++28 +-2 +-2 ++7 +-19 ++29 ++4 ++2 +14 --5 +-6 ++22 +14 -+11 --5 -+1 +-11 ++16 -13 -+1 -+18 +-15 ++4 +-9 +-20 +-36 +-17 +-7 -10 -+25 ++183 +-9 +13 +-108 ++34 +-138 +-65 +-42 +-4 ++10 ++410 ++75921 +-9 ++18 -17 -+15 --18 -+1 -6 --12 -+5 --7 -+18 ++15 ++6 ++12 +-13 +-4 +-8 +-16 ++15 -6 -18 --17 --5 --15 +-6 +-11 ++4 ++3 -1 --15 -+1 --12 -+9 +-9 +16 -+8 +5 +-6 +-4 +1 -+9 -+18 --13 --30 --27 --19 -+2 --16 --19 --10 --18 -+21 -+18 --5 +14 -+9 --6 -+2 ++20 -16 ++3 ++6 ++15 ++18 -11 ++15 +-14 +-14 +-8 ++9 +1 +-15 +-17 +18 --4 +-9 +-14 +19 -+7 -+6 +-1 ++10 ++14 -8 -+25 --50 -+6 --21 ++20 ++17 ++17 ++12 +-10 ++11 ++13 +-9 +6 --2 +14 --11 -+10 --9 -+16 -+25 --61 --17 --14 -+13 -+3 --14 +-16 +-10 -4 --1 -+9 --1 +-2 -4 --5 -+7 --15 -+7 -+16 -+6 ++8 ++13 ++13 +-17 ++9 -2 +-6 ++9 ++15 ++17 ++18 +-6 +-16 ++6 ++8 ++1 ++9 ++20 +-19 ++3 +-7 +-1 +-19 ++4 +-6 -11 --11 --13 -+11 -12 --13 --8 ++10 ++9 +3 --13 -+16 ++10 ++10 -1 ++18 +-8 -14 -+19 -+4 -+10 +-22 +12 -+26 -+6 -+4 -+24 --31 -+9 -10 --23 +-10 ++2 ++12 -13 -+3 --18 --9 --6 -+1 --2 +-7 +15 --10 --17 --17 +-3 ++7 +15 -+9 -+4 -+19 ++20 ++14 ++6 +-2 +-20 ++13 -4 -+12 ++18 +-2 +-8 +11 --25 +16 -+4 --2 -+39 -+49 -+9 -+96 -+4 ++8 +-9 +19 -+3 -+11 -+25 -+14 -+11 --5 --26 --8 -16 -+11 -+2 -+2 --1 ++9 ++19 ++7 +-13 ++7 -10 --45 --160 --31 --3 --43 +-14 -18 -+19 -+3 -+4 +-12 ++18 +11 +-15 +-3 ++16 +-8 ++18 +-9 ++20 -16 --19 --22 -+6 -+2 -+10 --11 --17 -+7 -+1 -+15 -+17 --19 -+6 --26 --7 --9 -+19 -+2 -+6 --22 -+2 +-6 +-16 +-2 +-10 +-8 -8 -+5 -+7 +9 -+8 --16 -+2 --19 +-15 ++13 +-20 +-7 +-5 +-13 -19 --3 -+16 -+5 -+4 --18 +-2 ++7 +-6 +-10 +-14 +-17 -11 --19 -+16 ++6 +-14 -15 ++24 ++11 +-10 +-16 ++10 +-1 ++14 +7 +-18 ++17 ++11 ++11 -1 --9 -19 +-10 +11 --17 --5 -+7 --11 -+16 +-15 ++11 +-4 +-16 ++10 +-15 ++24 ++6 ++6 +-26 -19 -+5 ++7 +21 --2 -+12 -+14 --7 -+18 ++22 ++26 +-18 ++8 ++34 +-12 -8 -+10 --11 --17 ++28 +-1 ++34 +-10 +3 --13 -+19 +-6 ++25 ++11 -3 -+10 ++20 ++9 ++8 +-14 ++16 +17 +-11 ++10 ++4 +-10 +-6 ++8 ++11 ++1 ++2 +-5 +-10 ++2 ++15 +-13 ++10 +17 --18 -+7 --2 --2 +-1 ++3 ++19 +-14 +12 --6 ++7 ++5 +-1 ++11 +19 --20 --15 --11 --27 -+8 +-12 ++16 +-7 +-18 ++12 +18 ++10 +-2 +-16 +-16 +-16 +-13 +9 --1 +-8 ++1 ++17 -2 -+19 -+7 ++5 ++9 +12 -+32 -+14 +-17 +13 --9 --14 -+20 ++1 ++14 +18 --4 --49 ++1 ++3 -6 +-5 ++1 +-17 +-13 +-9 +-15 +-23 -10 --7 ++1 ++13 ++4 +-5 +-2 ++9 +-1 +-10 +-15 -4 -9 ++17 ++1 -6 --37 ++15 ++8 ++1 -21 --2 +-4 ++3 +-18 ++20 +5 -+12 ++26 +4 --33 --4 --13 --4 -+13 --19 --7 --16 --1 --1 ++19 +8 --14 --15 -+11 ++19 ++20 +-9 -10 --14 --22 --11 -+10 --3 -+7 -+9 --15 +-12 +-12 +16 --7 --1 -+2 +-8 +-5 +-16 +-17 +20 -+11 --1 -+6 +-16 ++8 +-10 ++14 -2 ++15 ++22 ++4 +3 ++20 ++2 +3 ++16 ++14 +-3 ++5 ++12 +-7 +-18 +2 --20 --10 -+11 --10 -+13 --1 -+20 -+7 -+7 ++14 ++4 +-11 ++1 +5 ++6 +-4 ++16 ++11 +-14 ++18 +-7 ++14 +1 -+4 --13 -+15 +-19 -3 -+2 ++18 ++6 ++16 ++7 +-9 ++16 ++7 ++10 -4 --3 --1 -+13 +-4 +-12 -15 --14 --2 --6 -+3 +-16 ++7 ++19 ++11 ++18 ++7 +-12 +-12 ++20 +13 -19 --11 +-6 +-10 ++13 +-7 +-14 +-15 +-17 +-5 ++14 ++6 +8 --21 --2 --23 +-7 +-15 +-11 -18 -+20 -+7 -+6 --28 -+7 --33 -+13 +-16 -16 -18 --10 -18 ++7 ++22 +13 +-1 ++10 ++18 +-9 +-16 ++3 +-12 +-10 ++6 +8 --14 --13 ++14 +-19 -2 -+4 --14 ++13 ++5 ++8 ++7 ++5 ++5 ++7 ++17 +-4 -7 ++5 +-16 ++15 -18 --20 --4 --5 ++4 ++6 ++5 ++14 ++27 ++5 +-11 +-7 +-7 ++15 ++7 +-17 +8 +-14 +-3 ++2 ++25 ++12 +-6 +-17 ++7 +-8 ++23 -4 -+16 -+21 +20 ++18 ++4 +-9 ++3 +-20 -8 ++40 +-35 +-39 +-42 ++13 +-48 -14 --2 --14 --22 -+14 -+36 -+32 --28 -+1 ++7 ++19 -21 -+8 ++10 +-19 ++1 +-11 ++12 +-25 +-9 +-19 ++23 ++1 ++22 +-3 ++22 +-7 +14 -+75784 \ No newline at end of file +-25 ++66 +-8 ++104 ++41 ++35 ++1 ++11 +-48 +-38 ++44 +-64 ++259 +-17 ++19 +-16 ++12 ++16 +-77039 \ No newline at end of file From 7b077cf779856effef72ffc8d77161713d5d6641 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 27 Oct 2026 16:52:27 +0000 Subject: [PATCH 61/63] feat: implement frequency calculation from input file --- Sprint-1/stretch/aoc-2018-day1/solution.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-1/stretch/aoc-2018-day1/solution.js b/Sprint-1/stretch/aoc-2018-day1/solution.js index e69de29bb..3dcc90ab0 100644 --- a/Sprint-1/stretch/aoc-2018-day1/solution.js +++ b/Sprint-1/stretch/aoc-2018-day1/solution.js @@ -0,0 +1,12 @@ +const fs = require("fs"); +const lines = fs.readFileSync("input.txt", "utf8").split("\n"); + +let frequency = 0; + +for (const line of lines) { + if (line !== "") { + frequency += Number(line); + } +} +console.log(frequency); + From ec97a6d36850a3e78678a052d11ddb7346e5d6b8 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 27 Oct 2026 17:10:36 +0000 Subject: [PATCH 62/63] feat: update frequency calculation to handle input parsing and duplicates --- Sprint-1/stretch/aoc-2018-day1/solution.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Sprint-1/stretch/aoc-2018-day1/solution.js b/Sprint-1/stretch/aoc-2018-day1/solution.js index 3dcc90ab0..fe4019862 100644 --- a/Sprint-1/stretch/aoc-2018-day1/solution.js +++ b/Sprint-1/stretch/aoc-2018-day1/solution.js @@ -1,12 +1,16 @@ const fs = require("fs"); -const lines = fs.readFileSync("input.txt", "utf8").split("\n"); +const changes = fs.readFileSync("input.txt", "utf8").trim().split("\n").map(Number); let frequency = 0; -for (const line of lines) { - if (line !== "") { - frequency += Number(line); - } -} -console.log(frequency); +const seen = new Set([0]); +for (i = 0; ;i++) { + frequency += changes[i % changes.length]; + + if (seen.has(frequency)) { + console.log(frequency); + break; +} + seen.add(frequency) +} From 8a56804d0ce20aa343a676e1d19df2f558d5ba84 Mon Sep 17 00:00:00 2001 From: MattCarolus10 Date: Tue, 27 Oct 2026 17:22:10 +0000 Subject: [PATCH 63/63] remove prep from sprint branch --- prep/doubleAllNumbers.js | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 prep/doubleAllNumbers.js diff --git a/prep/doubleAllNumbers.js b/prep/doubleAllNumbers.js deleted file mode 100644 index 58045564e..000000000 --- a/prep/doubleAllNumbers.js +++ /dev/null @@ -1,13 +0,0 @@ -function doubleAllNumbers() { - let doubledNumbers; - - for (let n of numbers) { - doubledNumbers.push(n * 2); - } - - return doubledNumbers; -} - -const myNums = [10, 20, 30]; -doubleAllNumbers(myNums); -console.log(myNums);