From 10f634599898f0ad644e6f6b8705bc34d3b696a2 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Tue, 9 Sep 2025 23:52:41 +0100 Subject: [PATCH 1/8] fix: correct calculateMedian implementation - Properly calculates median for odd and even-length arrays - Handles unsorted arrays - Filters out non-numeric values - Returns null for invalid or empty inputs - Ensures the input array is not modified --- Sprint-1/fix/median.js | 27 ++++++++++++++++++--------- Sprint-1/fix/package.json | 8 ++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 Sprint-1/fix/package.json diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b22590bc6..5994aa855 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -1,14 +1,23 @@ -// 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 +function calculateMedian(list) { + if (!Array.isArray(list) || list.length === 0) return null; -// Hint: Please consider scenarios when 'list' doesn't have numbers (the function is expected to return null) -// or 'list' has mixed values (the function is expected to sort only numbers). + // Filter out non-number values + const numbers = list.filter(item => typeof item === "number"); + if (numbers.length === 0) return null; -function calculateMedian(list) { - const middleIndex = Math.floor(list.length / 2); - const median = list.splice(middleIndex, 1)[0]; - return median; + // Sort numbers in ascending order + numbers.sort((a, b) => a - b); + + const middleIndex = Math.floor(numbers.length / 2); + + // If odd number of elements, return middle + if (numbers.length % 2 !== 0) { + return numbers[middleIndex]; + } + + // If even, return average of two middle numbers + return (numbers[middleIndex - 1] + numbers[middleIndex]) / 2; } module.exports = calculateMedian; + diff --git a/Sprint-1/fix/package.json b/Sprint-1/fix/package.json new file mode 100644 index 000000000..d94074e93 --- /dev/null +++ b/Sprint-1/fix/package.json @@ -0,0 +1,8 @@ +{ + "devDependencies": { + "jest": "^30.1.3" + }, + "scripts": { + "test": "jest" + } +} From a3e3a13a1b295af4128b2dc27fbdff7e630c704a Mon Sep 17 00:00:00 2001 From: Samiuk Date: Tue, 9 Sep 2025 23:58:27 +0100 Subject: [PATCH 2/8] feat: implement dedupe function with tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added dedupe.js to remove duplicate elements from arrays while preserving first occurrence - Handles empty arrays, arrays with numbers, strings, or mixed values - Added dedupe.test.js covering: • empty array • arrays with no duplicates • arrays with duplicate strings, numbers, and mixed values - Ensures original array is not modified --- Sprint-1/implement/dedupe.js | 19 ++++++++++++- Sprint-1/implement/dedupe.test.js | 44 +++++++++++++++++-------------- Sprint-1/implement/package.json | 8 ++++++ 3 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 Sprint-1/implement/package.json diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..f8a2c8b4e 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,18 @@ -function dedupe() {} +function dedupe(arr) { + if (!Array.isArray(arr)) return []; + + const seen = new Set(); + const result = []; + + for (const item of arr) { + if (!seen.has(item)) { + seen.add(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 23e0f8638..f13a1e3b2 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -1,27 +1,31 @@ const dedupe = require("./dedupe.js"); -/* -Dedupe Array +describe("dedupe function", () => { -📖 Dedupe means **deduplicate** + // Test 1: empty array + test("given an empty array, it returns an empty array", () => { + expect(dedupe([])).toEqual([]); + }); -In this kata, you will need to deduplicate the elements of an array + // Test 2: array with no duplicates + test("given an array with no duplicates, it returns a copy of the original array", () => { + const arr = [1, 2, 3, 4]; + expect(dedupe(arr)).toEqual(arr); + expect(dedupe(arr)).not.toBe(arr); // ensure it returns a new array, not the same reference + }); -E.g. dedupe(['a','a','a','b','b','c']) target output: ['a','b','c'] -E.g. dedupe([5, 1, 1, 2, 3, 2, 5, 8]) target output: [5, 1, 2, 3, 8] -E.g. dedupe([1, 2, 1]) target output: [1, 2] -*/ + // Test 3: array with duplicates (strings) + test("removes duplicate strings, preserving first occurrence", () => { + expect(dedupe(['a', 'a', 'a', 'b', 'b', 'c'])).toEqual(['a', 'b', 'c']); + }); -// Acceptance Criteria: + // Test 4: array with duplicates (numbers) + test("removes duplicate numbers, preserving first occurrence", () => { + expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]); + }); -// 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 5: mixed array + test("removes duplicates in mixed arrays", () => { + expect(dedupe([1, 2, 1])).toEqual([1, 2]); + }); -// 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 with strings or numbers -// When passed to the dedupe function -// Then it should remove the duplicate values, preserving the first occurence of each element +}); diff --git a/Sprint-1/implement/package.json b/Sprint-1/implement/package.json new file mode 100644 index 000000000..d94074e93 --- /dev/null +++ b/Sprint-1/implement/package.json @@ -0,0 +1,8 @@ +{ + "devDependencies": { + "jest": "^30.1.3" + }, + "scripts": { + "test": "jest" + } +} From e2e920fdfa73a8475a704d05321b27d055f04d59 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Wed, 10 Sep 2025 00:00:41 +0100 Subject: [PATCH 3/8] feat: implement findMax function with tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added max.js to find the largest numerical element in an array - Ignores non-numeric values - Handles empty arrays, negative numbers, decimal numbers, and mixed-type arrays - Added max.test.js covering: • empty array • single-element array • positive and negative numbers • decimal numbers • arrays with non-number values • arrays with only non-number values --- Sprint-1/implement/max.js | 14 +++++++- Sprint-1/implement/max.test.js | 65 ++++++++++++++++------------------ 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..04a7b56e5 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,16 @@ -function findMax(elements) { +function findMax(arr) { + if (!Array.isArray(arr) || arr.length === 0) return -Infinity; + + let max = -Infinity; + + for (const item of arr) { + if (typeof item === "number" && item > max) { + max = item; + } + } + + return max; } module.exports = findMax; + diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 82f18fd88..4e5abc040 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -1,43 +1,40 @@ -/* 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]), target output: 60 (sum ignores any non-numerical elements) - -You should implement this function in max.js, and add tests for it in this file. +const findMax = require("./max.js"); -We have set things up already so that this file can see your function from the other file. -*/ +describe("findMax function", () => { -const findMax = require("./max.js"); + // Test 1: empty array + test("given an empty array, returns -Infinity", () => { + expect(findMax([])).toBe(-Infinity); + }); -// 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.todo("given an empty array, returns -Infinity"); + // Test 2: array with one number + test("given an array with one number, returns that number", () => { + expect(findMax([42])).toBe(42); + }); -// Given an array with one number -// When passed to the max function -// Then it should return that number + // Test 3: array with positive and negative numbers + test("returns the largest number from mixed positive and negative numbers", () => { + expect(findMax([3, -2, 7, -10, 5])).toBe(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 4: array with only negative numbers + test("returns the closest number to zero for negative numbers", () => { + expect(findMax([-10, -2, -30])).toBe(-2); + }); -// Given an array with just negative numbers -// When passed to the max function -// Then it should return the closest one to zero + // Test 5: array with decimal numbers + test("returns the largest decimal number", () => { + expect(findMax([1.1, 2.5, 2.49])).toBe(2.5); + }); -// Given an array with decimal numbers -// When passed to the max function -// Then it should return the largest decimal number + // Test 6: array with non-number values + test("ignores non-numeric values and returns the largest number", () => { + expect(findMax([10, "apple", 20, null, 5])).toBe(20); + }); -// Given an array with non-number values -// When passed to the max function -// Then it should return the max and ignore non-numeric values + // Test 7: array with only non-number values + test("array with only non-number values returns -Infinity", () => { + expect(findMax(["a", null, "b"])).toBe(-Infinity); + }); -// Given an array with only non-number values -// When passed to the max function -// Then it should return the least surprising value given how it behaves for all other inputs +}); From 537861b3c10b3d87d3e26826378b14a076531474 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Wed, 10 Sep 2025 00:04:40 +0100 Subject: [PATCH 4/8] feat: implement sum function with tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added sum.js to calculate the total sum of numerical elements in an array - Ignores non-numeric values - Handles empty arrays, negative numbers, decimal numbers, and mixed-type arrays - Added sum.test.js covering: • empty array • single-element array • positive and negative numbers • decimal numbers • arrays with non-number values • arrays with only non-number values --- Sprint-1/implement/sum.js | 8 ++++- Sprint-1/implement/sum.test.js | 55 +++++++++++++++++----------------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..3230f93a1 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,10 @@ -function sum(elements) { +function sum(arr) { + if (!Array.isArray(arr)) return 0; + + return arr.reduce((total, item) => { + return typeof item === "number" ? total + item : total; + }, 0); } module.exports = sum; + diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index dd0a090ca..58a027bbb 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -1,36 +1,35 @@ -/* 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]), target output: 80 (ignore any non-numerical elements) -*/ - const sum = require("./sum.js"); -// Acceptance Criteria: +describe("sum function", () => { + + // Test 1: empty array + test("given an empty array, returns 0", () => { + expect(sum([])).toBe(0); + }); -// Given an empty array -// When passed to the sum function -// Then it should return 0 -test.todo("given an empty array, returns 0") + // Test 2: array with one number + test("given an array with one number, returns that number", () => { + expect(sum([42])).toBe(42); + }); -// Given an array with just one number -// When passed to the sum function -// Then it should return that number + // Test 3: array with positive and negative numbers + test("returns the correct total sum for positive and negative numbers", () => { + expect(sum([10, -5, 15, -3])).toBe(17); + }); -// Given an array containing negative numbers -// When passed to the sum function -// Then it should still return the correct total sum + // Test 4: array with decimal numbers + test("returns the correct total sum for decimal/float numbers", () => { + expect(sum([1.5, 2.3, 3.2])).toBeCloseTo(7.0); // Use toBeCloseTo for floating points + }); -// Given an array with decimal/float numbers -// When passed to the sum function -// Then it should return the correct total sum + // Test 5: array with non-number values + test("ignores non-numeric values and sums numerical elements", () => { + expect(sum([10, "a", 20, null, 5])).toBe(35); + }); -// Given an array containing non-number values -// When passed to the sum function -// Then it should ignore the non-numerical values and return the sum of the numerical elements + // Test 6: array with only non-number values + test("returns 0 if there are no numeric elements", () => { + expect(sum(["a", null, "b"])).toBe(0); + }); -// Given an array with only non-number values -// When passed to the sum function -// Then it should return the least surprising value given how it behaves for all other inputs +}); From c4e5da6b6ea03c3cec089eba369c83eb93c566d7 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Wed, 10 Sep 2025 00:11:00 +0100 Subject: [PATCH 5/8] =?UTF-8?q?refactor:=20update=20includes=20function=20?= =?UTF-8?q?to=20use=20for...of=20loop=20-=20Refactored=20includes.js=20to?= =?UTF-8?q?=20iterate=20over=20array=20elements=20using=20a=20for...of=20l?= =?UTF-8?q?oop=20-=20Preserves=20original=20behavior:=20=20=20=E2=80=A2=20?= =?UTF-8?q?returns=20true=20if=20target=20is=20found=20=20=20=E2=80=A2=20r?= =?UTF-8?q?eturns=20false=20if=20target=20is=20not=20found=20-=20All=20exi?= =?UTF-8?q?sting=20tests=20in=20includes.test.js=20remain=20passing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sprint-1/refactor/includes.js | 7 +++---- Sprint-1/refactor/package.json | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 Sprint-1/refactor/package.json diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..7f16356da 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 - +// Check if a list includes a target value 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; } @@ -11,3 +9,4 @@ function includes(list, target) { } module.exports = includes; + diff --git a/Sprint-1/refactor/package.json b/Sprint-1/refactor/package.json new file mode 100644 index 000000000..d94074e93 --- /dev/null +++ b/Sprint-1/refactor/package.json @@ -0,0 +1,8 @@ +{ + "devDependencies": { + "jest": "^30.1.3" + }, + "scripts": { + "test": "jest" + } +} From d4ae6ff3ac5a08d9d9904beabdcdab774071e4d0 Mon Sep 17 00:00:00 2001 From: Samiuk Date: Wed, 10 Sep 2025 00:31:53 +0100 Subject: [PATCH 6/8] - add Advent of Code Day 1 solution - Implemented calculation of final frequency. - Implemented detection of first repeated frequency. - Reads input from input.txt and logs results to console. --- Sprint-1/stretch/aoc-2018-day1/input.txt | 1456 ++++++++++---------- Sprint-1/stretch/aoc-2018-day1/solution.js | 26 + 2 files changed, 761 insertions(+), 721 deletions(-) diff --git a/Sprint-1/stretch/aoc-2018-day1/input.txt b/Sprint-1/stretch/aoc-2018-day1/input.txt index 1ffa65fc8..8b27667ca 100644 --- a/Sprint-1/stretch/aoc-2018-day1/input.txt +++ b/Sprint-1/stretch/aoc-2018-day1/input.txt @@ -1,951 +1,965 @@ --10 --12 -+1 -+14 -+11 --19 --4 -+10 -+10 --12 --13 --10 --8 -+11 -+3 --10 -+8 -+5 ++15 -14 -+7 -+12 -+12 -+14 --1 -+17 --5 -+9 --15 -+8 --16 -+9 -+6 -+17 --11 -+19 -+11 -9 +-15 ++5 -1 --8 +-6 ++5 +-19 +-11 ++13 +-20 +-5 +-19 -16 -5 -+6 +-5 +-7 ++16 ++3 ++7 ++16 +2 -+6 ++5 ++10 ++13 +-4 +-17 ++4 +-8 +-18 ++16 +-14 ++3 +12 ++8 +15 -+16 --6 --8 --5 -+11 --9 -+19 -+19 --5 --12 --17 --20 -+9 --6 --2 -+20 +15 -8 -+15 +-6 ++9 ++2 ++16 +19 --5 --17 --9 -+1 --9 ++18 +-6 ++13 ++7 +-12 -11 --19 --1 ++19 +-20 -15 -+18 --4 +-19 +-10 +19 +3 -+21 -+5 ++6 ++15 -1 -+8 -+9 -+9 --16 +-5 ++3 +-1 ++14 +17 --15 +-4 +18 -+14 -+8 --13 --2 --15 -+13 +19 ++6 -13 -+5 -+16 -+16 ++12 ++2 +7 -+8 --19 -+3 --12 -+18 --16 --19 -+8 --16 -+20 -+15 -5 ++3 -17 +15 -+14 --2 -+18 --6 -+5 -+16 -+13 --8 --9 --1 -+13 ++8 +18 --2 -+16 --4 -+19 -+6 -+14 --6 --16 --10 --5 --15 +-19 +11 -+10 -+18 -+8 --2 -+15 --9 +-8 ++5 +-17 ++7 +7 ++17 +-13 +-7 +10 -+9 -6 -+1 --17 --12 +19 -+14 --9 --18 +-12 +20 +-19 +-10 ++17 +-14 +-8 +-13 +-2 +-15 +-11 +-6 ++3 +12 -+10 +14 +6 +9 --18 -+4 -+15 -+15 ++20 ++21 ++16 +-14 ++1 +3 -+9 --4 --19 +8 -+16 -+19 --12 ++3 +-18 +-5 ++14 +-3 ++7 ++17 -1 -+16 -+11 +-1 +-4 +13 ++5 ++11 ++15 ++5 ++14 +-12 ++5 +-13 +-19 -8 -+4 +-18 ++16 ++12 ++13 +18 +10 --11 +18 -8 -+19 --4 --5 --12 --3 --10 --11 --18 --7 -+3 -+14 -+18 -+2 --7 +-8 ++17 -12 ++4 +-14 ++6 ++17 +14 -+12 -+13 -1 -+13 --1 -+15 -+13 ++7 ++7 ++4 +-8 ++10 +-12 ++14 ++6 ++6 -1 +-6 +-3 ++12 ++12 +-8 -17 -4 -+17 +-4 +-9 -3 -+13 -+5 --19 -+17 -+10 -+6 --15 -+11 -+16 -+11 -+20 -+19 -+5 +-1 -11 ++14 ++6 -2 ++16 +-9 -12 --6 --11 --14 +-8 +-1 +-2 +5 -+10 --23 -+14 --11 -+22 ++19 ++15 -1 ++18 ++8 ++14 ++14 +-19 -14 --35 --23 -+11 -+4 -+10 --6 -+19 -5 +-18 ++12 +4 +-6 +-2 ++1 +-8 +-9 ++5 ++9 ++23 ++6 ++10 ++18 -13 ++19 -7 +11 --24 --17 -+9 --17 -+11 -+2 --4 --10 --24 -+14 +-1 ++17 ++18 ++16 +15 ++12 ++16 +-8 +-4 +19 -+7 --2 +11 --13 --8 --8 --14 --17 -+6 -+8 --16 --18 -+1 --21 --14 -+8 --2 -+20 -19 -+9 --15 --6 --7 -+4 --3 --8 -+16 +-12 +15 --26 -+18 --22 --16 --3 --17 --18 -+4 -+5 +3 -1 -+3 -+2 -+3 -+7 --5 -+20 +-1 +-13 +-13 -11 -+15 --6 --19 --24 --6 --20 +13 --4 --18 +-19 +15 -+9 -+16 -+12 --5 +16 -+9 --4 --14 --9 --19 --5 --16 --16 -+5 --4 -+12 --15 --15 --14 -+4 --18 --12 --4 -+6 -+9 --12 -+14 -+9 --6 -+3 -+8 -+4 +7 --14 +-17 ++4 +-2 -15 --18 -+12 --19 --14 ++10 ++4 ++19 -15 -16 -+15 --8 -+14 --4 --21 -+7 +-17 ++5 -12 ++16 +-17 +-18 ++7 +-14 -2 -10 --6 -+14 -+14 +-8 ++16 ++13 ++18 -9 --14 --16 +2 -+7 -+5 -15 ++8 ++6 +-3 -15 -+19 -16 ++9 ++10 -5 +-10 ++19 -16 ++18 -19 -+9 --27 --8 -+6 -+1 --14 -9 --50 --9 --21 -+5 +-15 -20 --19 -+6 --11 -+6 -+1 --17 --14 ++13 ++15 +-13 +-7 ++13 -2 -+8 --4 -+16 -+1 --3 --9 -+20 -+15 --22 --3 --13 --12 --25 -+5 --13 --2 --8 --11 -+17 ++18 +-21 ++6 +3 -7 -+13 -+1 -+18 +-15 ++2 ++19 +-13 ++15 +-19 +-14 -13 +1 +7 ++26 +-13 +-19 ++7 ++8 ++1 ++8 -15 --43 ++3 +-44 +-15 +-15 ++10 +-11 ++9 +-2 +-5 +-15 ++3 +-10 +-2 +-14 +-10 +-1 ++4 -6 -10 --9 --20 --7 --8 -15 --9 -+13 --9 -+24 ++8 ++15 ++11 +-18 +13 ++17 ++2 ++11 ++7 ++6 +-14 +-15 +-10 +-13 +-6 +-18 +-1 +-10 +-17 +-18 +-2 ++8 ++4 +5 +-6 -8 --15 --4 --4 ++11 ++1 +-20 ++28 +-10 -4 ++17 ++3 ++4 -14 --21 ++21 ++2 ++4 +16 ++8 ++17 +-22 +-11 ++10 ++9 ++18 +-15 ++16 ++13 +-2 ++31 +-14 ++1 ++4 +-8 +-18 +-17 +15 ++10 -14 --20 --20 ++36 ++62 ++15 +-7 ++18 ++21 ++19 ++14 ++6 -15 ++20 ++2 +-9 ++8 ++20 ++4 +-15 ++12 +-15 ++16 +-14 ++10 ++10 +-2 +-13 ++37 -19 --41 ++2 ++4 +16 ++19 ++7 ++18 ++1 +-11 +-13 +-9 +3 -+8 --22 --30 -+8 -+40 -+15 -+24 --7 -+22 ++5 ++16 +-20 ++16 +10 -+15 +9 -+28 -+14 ++10 +-12 +-14 ++19 +-1 ++6 ++7 ++21 ++10 ++17 ++2 ++7 ++9 +-1 ++4 +-11 +-5 +-14 ++4 +-17 +2 +-10 +14 +-2 +6 -+17 -+1 -+30 ++16 ++11 +5 --2 -+46 -+24 -+46 ++32 ++18 +-11 ++7 +-6 +-16 +-20 ++6 -3 --7 -+35 ++21 +-5 ++21 +16 -+13 --21 -+28 -+13 --25 -+180 -+25 +5 -9 -+23 ++6 ++15 +-19 ++11 +-10 +-17 ++26 -5 --2 +-9 +-19 +13 --12 -+2 --25 ++24 ++7 -5 ++8 +-12 +-13 ++19 ++15 +-20 +-4 +-31 +-7 +-21 ++1 +18 --24 -+45 +-12 ++3 ++16 +17 ++66 ++30 ++21 +-15 ++3 ++13 +-4 ++2 ++23 +-46 +-1 +-203 ++15 ++2 +-22 ++2 +-13 +-2 +-23 +-16 +-16 +-8 ++21 ++9 ++2 ++3 ++2 ++11 +-4 +-13 ++3 ++19 -7 -+22 --152 ++13 ++3 ++24 ++14 +-21 ++9 +-18 ++5 +-50 +-19 +-36 -11 -+4 -+50 -+129 --7 +-22 +-16 +22 -+109 --56 -+80 -+29 --75060 --2 --14 -+7 -17 --5 -+6 --3 -+18 -+19 +-21 ++7 ++12 -14 ++55 +-4 ++5 ++51 ++30 ++27 ++69 +-23 ++4 +-13 +-34 +-41 +-31 ++15 +-36 +-169 ++14 +-19 +-214 ++16 +-79870 ++16 -12 ++17 ++15 -6 +-7 ++18 ++13 ++11 ++18 ++18 +-9 ++19 ++11 +-12 +-3 ++18 +-13 ++19 ++11 ++8 +-4 +9 --5 ++10 +-12 +-20 +-18 ++3 ++19 +-3 ++11 ++12 ++3 +-8 +-11 +-2 +-12 +-8 +-21 +-20 +-12 -13 ++19 +-14 ++15 ++17 +-5 +-17 ++13 +-18 +-18 +-3 +-2 ++6 +-8 ++9 +-4 +-10 +-15 -6 +-5 ++3 +-20 ++11 +-20 ++2 +-12 -3 ++7 -15 -+13 +3 --18 --11 -+16 --2 -+10 +-13 -14 --7 +-6 +-6 ++10 ++11 +19 --20 ++10 +-17 +-17 +-11 +-11 ++3 +-13 +15 ++20 +10 +-16 ++7 ++7 +-4 +-16 ++2 ++8 ++18 +-1 ++3 ++15 ++15 +-19 +12 -+10 -+16 --11 -+14 -5 +-10 ++19 +14 -+11 --5 +1 ++14 +-24 +-4 +-19 +-15 -13 -+1 -+18 -10 -+25 -+13 --17 -+15 -18 -+1 --6 -12 -+5 --7 -+18 -6 --18 +-8 -17 --5 --15 --1 -15 -+1 --12 -+9 ++10 +16 -+8 -+5 -+1 -+9 -+18 --13 --30 --27 --19 -+2 --16 --19 --10 -18 -+21 ++12 +-16 +-9 +-6 ++17 ++19 +18 -5 -+14 -+9 --6 -+2 --16 ++4 ++13 -11 -+1 -+18 --4 +-17 ++8 +19 -+7 -+6 --8 -+25 --50 -+6 --21 -+6 --2 -+14 --11 +10 +-5 +-2 -9 -+16 -+25 --61 --17 --14 -+13 +3 --14 --4 --1 -+9 --1 --4 --5 -+7 --15 -+7 -+16 -+6 -2 --11 --11 --13 -+11 --12 --13 -8 -+3 +-19 -13 -+16 ++8 ++2 +-14 +-9 +-14 +-16 -1 -14 -+19 -+4 -+10 -+12 -+26 -+6 -+4 -+24 --31 -+9 --10 --23 --13 +3 +-8 +-6 -18 --9 +-7 ++6 ++14 -6 +-19 +-18 ++3 +-7 +-1 +-12 +-12 +1 --2 -+15 --10 --17 --17 +15 -+9 -+4 +19 --4 -+12 -+11 --25 +-7 +16 -+4 --2 -+39 -+49 -+9 -+96 -+4 -+19 -+3 -+11 -+25 +-10 +-7 +-12 ++7 +-18 +-12 +-11 ++8 +-12 +-16 +-15 +-9 ++14 +-19 +-3 +-1 +-9 +-14 ++7 +14 ++15 +11 ++8 +-1 ++8 +-18 -5 --26 --8 --16 -+11 -+2 -+2 +-1 +-12 ++5 ++9 ++9 ++15 ++14 ++12 -1 -10 --45 --160 --31 --3 --43 ++13 -18 +19 -+3 -+4 -+11 --16 --19 --22 -+6 -+2 -+10 -11 --17 -+7 -+1 -+15 -+17 --19 +6 --26 -7 --9 -+19 -+2 -+6 --22 -+2 --8 +-11 +-4 +-6 +5 -+7 -+9 -+8 +-14 +-1 +-20 +-18 +-16 -16 -+2 --19 --19 -3 -+16 +-4 ++6 +-4 ++1 +-11 +5 +-10 ++21 ++6 ++11 +-14 +4 --18 --11 --19 -+16 --15 -+7 --1 --9 --19 ++2 ++15 +11 --17 --5 -+7 --11 -+16 ++6 ++3 +-10 ++13 +-10 -19 -+5 -+21 -2 ++11 ++9 +12 +14 +-9 ++1 +-2 ++9 ++10 -7 +18 --8 -+10 --11 --17 ++14 +-10 +-14 ++5 ++11 +-12 ++11 ++5 ++7 ++21 ++4 +-14 +3 --13 -+19 --3 -+10 -+17 +-9 +17 --18 -+7 --2 +-16 ++20 -2 -+12 -6 -+19 --20 --15 ++10 ++6 ++12 -11 --27 -+8 -+18 -+9 --1 --2 +19 -+7 ++10 +-13 ++5 +12 -+32 -+14 -+13 --9 --14 +-13 +-2 +-1 +-16 +-19 ++16 ++24 +20 -+18 --4 --49 --6 --10 --7 --4 --9 +-5 -6 --37 --21 --2 -+5 -+12 +4 --33 --4 ++1 +-8 +-18 -13 --4 +-12 +-29 +-12 ++24 +-35 +13 --19 +-24 +-18 +-9 -7 --16 --1 --1 ++17 +-11 +-17 +-20 +-4 +-5 +8 --14 --15 -+11 --10 --14 --22 +-13 +-1 +-7 +-9 -11 ++8 +-16 +10 --3 -+7 -+9 -15 -+16 --7 --1 -+2 -+20 -+11 --1 -+6 --2 -+3 -+3 -+2 --20 --10 ++12 +-3 +11 +-13 +-4 -10 -+13 --1 -+20 -+7 -+7 -+5 +1 +4 +-18 ++10 -13 -+15 --3 -+2 +-16 +-7 +-17 -4 --3 -1 -+13 --15 --14 --2 --6 +-24 ++3 +3 -+13 --19 --11 -+8 --21 --2 --23 --18 -+20 -+7 -+6 --28 -+7 --33 -+13 --16 --18 -10 --18 -+13 +8 --14 --13 --2 -+4 --14 --7 +-9 ++6 -18 ++5 +-11 +-12 +-16 ++2 -20 --4 --5 -+8 --4 -+16 -+21 -+20 --8 --14 --2 --14 --22 ++23 +-7 ++19 +14 -+36 -+32 --28 -+1 --21 +-19 ++6 +8 +-1 ++17 ++2 +-15 ++19 +-3 +14 -+75784 \ No newline at end of file ++18 ++7 ++10 +-7 +-6 ++14 +-4 +-1 ++80922 \ No newline at end of file diff --git a/Sprint-1/stretch/aoc-2018-day1/solution.js b/Sprint-1/stretch/aoc-2018-day1/solution.js index e69de29bb..4afbac8f7 100644 --- a/Sprint-1/stretch/aoc-2018-day1/solution.js +++ b/Sprint-1/stretch/aoc-2018-day1/solution.js @@ -0,0 +1,26 @@ +const fs = require("fs"); + +// Load the input file +const input = fs.readFileSync("input.txt", "utf-8") + .split("\n") // Split by line + .filter(Boolean) // Remove empty lines + .map(Number); // Convert each line to a number + +function findFirstRepeatedFrequency(changes) { + const seen = new Set([0]); + let frequency = 0; + let index = 0; + + while (true) { + frequency += changes[index]; + if (seen.has(frequency)) { + return frequency; // First repeated frequency found + } + seen.add(frequency); + index = (index + 1) % changes.length; // Loop through the list + } +} + +const firstRepeated = findFirstRepeatedFrequency(input); +console.log("First frequency reached twice:", firstRepeated); + From 70d01d9d10491e37026ed23e424f3c487209624a Mon Sep 17 00:00:00 2001 From: Samiuk Date: Thu, 11 Sep 2025 00:50:09 +0100 Subject: [PATCH 7/8] Refactor calculateMedian to remove unnecessary splice and avoid mutating the array; retain numeric sort for correct median calculation --- Sprint-1/fix/median.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 5994aa855..f4179890a 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -18,6 +18,4 @@ function calculateMedian(list) { // If even, return average of two middle numbers return (numbers[middleIndex - 1] + numbers[middleIndex]) / 2; } - -module.exports = calculateMedian; - +module.exports = calculateMedian; \ No newline at end of file From aa274393b48d64f14fac89dea583fc4834ffb26d Mon Sep 17 00:00:00 2001 From: Samiuk Date: Thu, 11 Sep 2025 00:56:26 +0100 Subject: [PATCH 8/8] Remove unnecessary package.json from this branch --- Sprint-1/fix/package.json | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 Sprint-1/fix/package.json diff --git a/Sprint-1/fix/package.json b/Sprint-1/fix/package.json deleted file mode 100644 index d94074e93..000000000 --- a/Sprint-1/fix/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "devDependencies": { - "jest": "^30.1.3" - }, - "scripts": { - "test": "jest" - } -}