From ebc242eaa44a33c78be2c153b372f15983772aae Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 15:27:33 +0100 Subject: [PATCH 01/56] created package json --- Sprint-1/fix/package.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Sprint-1/fix/package.json diff --git a/Sprint-1/fix/package.json b/Sprint-1/fix/package.json new file mode 100644 index 000000000..bdef60590 --- /dev/null +++ b/Sprint-1/fix/package.json @@ -0,0 +1,18 @@ +{ + "name": "fix", + "version": "1.0.0", + "description": "", + "main": "median.js", + "scripts": { + "test": "jest" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "test": "^3.3.0" + }, + "devDependencies": { + "jest": "^30.2.0" + } +} From f1241139921e5f0fef07a688baf2b919868b0600 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 15:53:17 +0100 Subject: [PATCH 02/56] re wrote code to calculate median and pass all tests left comments explaining what the code does --- Sprint-1/fix/median.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b22590bc6..b91f22644 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,9 +6,28 @@ // or 'list' has mixed values (the function is expected to sort only numbers). function calculateMedian(list) { - const middleIndex = Math.floor(list.length / 2); - const median = list.splice(middleIndex, 1)[0]; - return median; + // check if its array and if has content + if (!Array.isArray(list) || list.length === 0) return null; + + // filter for valid numbers + const numbers = list.filter( + (item) => typeof item === "number" && !isNaN(item) + ); + + // if there's no numbers returns null + if (numbers.length === 0) return null; + + // sort without modifying the original + const sorted = [...numbers].sort((a, b) => a - b); + + // calculates median + const middle = Math.floor(sorted.length / 2); + + if (sorted.length % 2 === 0) { + return (sorted[middle - 1] + sorted[middle]) / 2; + } else { + return sorted[middle]; + } } module.exports = calculateMedian; From a77feba09f3131a31b34c1aab1ae1677114cd50b Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 16:24:41 +0100 Subject: [PATCH 03/56] wrote code following the guidelines node test to check if it works --- Sprint-1/implement/dedupe.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..145b26ca3 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,25 @@ -function dedupe() {} +function dedupe(arr) { + if (!Array.isArray(arr) || arr.length === 0){ + return []; + } + const unique = [...new Set(arr)]; + return unique; +} + +console.log(dedupe([])); // [] +console.log(dedupe([1, 2, 3])); // [1, 2, 3] +console.log(dedupe([1, 2, 2, 3, 1])); // [1, 2, 3] +console.log(dedupe(["apple", "banana", "apple", "orange"])); // ["apple", "banana", "orange"] +console.log(dedupe(["apple", 3, 5, 5, 9, 7, "banana", "orange", "orange"])); + +// Given an empty array +// When passed to the dedupe function +// Then it should return an empty array + +// Given an array with no duplicates +// When passed to the dedupe function +// Then it should return a copy of the original array + +// 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 From a2c06e6539e02da0c7ded01f77f26ff431398d78 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 16:48:30 +0100 Subject: [PATCH 04/56] installed package and dependencies wrote code to dedupe arrays and tested wrote tests , corrected and cleaned code --- Sprint-1/implement/dedupe.js | 22 ++++++++++++---------- Sprint-1/implement/dedupe.test.js | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 145b26ca3..4143d984f 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -10,16 +10,18 @@ console.log(dedupe([])); // [] console.log(dedupe([1, 2, 3])); // [1, 2, 3] console.log(dedupe([1, 2, 2, 3, 1])); // [1, 2, 3] console.log(dedupe(["apple", "banana", "apple", "orange"])); // ["apple", "banana", "orange"] -console.log(dedupe(["apple", 3, 5, 5, 9, 7, "banana", "orange", "orange"])); +console.log(dedupe(["apple", 3, 5, 5, 9, 7, "banana", "orange", "orange"])); // ["apple", 3, 5, 9, 7, "banana", "orange"] -// Given an empty array -// When passed to the dedupe function -// Then it should return an empty array +/*Given an empty array +When passed to the dedupe function +Then it should return an empty array*/ -// Given an array with no duplicates -// When passed to the dedupe function -// Then it should return a copy of the original array +/*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 +/*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*/ + +module.exports = dedupe; diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 23e0f8638..e456e1b28 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -1,4 +1,5 @@ const dedupe = require("./dedupe.js"); + /* Dedupe Array @@ -16,12 +17,21 @@ E.g. dedupe([1, 2, 1]) target output: [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.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 // Then it should return a copy of the original array - +test("given an array without duplicates, return the copy of original", () => { + expect(dedupe([1, 2, 5, 7, 9])).toEqual([1, 2, 5, 7, 9]); +}) // 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 +// Then it should remove the duplicate values, preserving the first occurrence of each element +test("given an array with strings or numbers, return the original without the repeated values", () => { + expect(dedupe(["apple", "apple", "pear", 2, 6, 6, 10, 11, 11, "banana"])).toEqual(["apple", "pear", 2, 6, 10, 11, "banana"]); +}) \ No newline at end of file From 2f4b642404d107611bcac1ffa861c574ebc7f55e Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 17:01:10 +0100 Subject: [PATCH 05/56] code for empty array and 1 number array --- Sprint-1/implement/max.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..216a53c71 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,37 @@ function findMax(elements) { + if ( elements.length === 0){ + return -Infinity; + } else if ( elements.length == 1) { + return elements; + } } +console.log(findMax([])); +// Given an empty array +// When passed to the max function +// Then it should return -Infinity + +// 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 with non-number values +// When passed to the max function +// Then it should return the max and ignore non-numeric values + +// 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 module.exports = findMax; From 179683b7cd44e8a02e5e261373b45cee4d33a804 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 18:28:05 +0100 Subject: [PATCH 06/56] code for non-number values --- Sprint-1/implement/max.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 216a53c71..8ebfdd246 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,11 +1,15 @@ function findMax(elements) { - if ( elements.length === 0){ + const onlyNumbers = elements.filter(x => typeof x === "number" && !isNaN(x)); + if (onlyNumbers.length < elements.length) { return -Infinity; - } else if ( elements.length == 1) { - return elements; - } + } if ( onlyNumbers.length === 0){ + return -Infinity; + } if ( onlyNumbers.length === 1) { + return onlyNumbers[0]; + } } -console.log(findMax([])); + +console.log(findMax([233])); // Given an empty array // When passed to the max function // Then it should return -Infinity From 82b7add09389eb81bc0699f6809fb0f0224f9357 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 18:36:58 +0100 Subject: [PATCH 07/56] finished code, and cleaned it tested node --- Sprint-1/implement/max.js | 41 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 8ebfdd246..35c1b084a 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,41 +1,22 @@ function findMax(elements) { const onlyNumbers = elements.filter(x => typeof x === "number" && !isNaN(x)); - if (onlyNumbers.length < elements.length) { - return -Infinity; - } if ( onlyNumbers.length === 0){ + // empty array + if ( onlyNumbers.length === 0){ return -Infinity; + // array with only one number } if ( onlyNumbers.length === 1) { return onlyNumbers[0]; } + return Math.max(...onlyNumbers); } -console.log(findMax([233])); -// Given an empty array -// When passed to the max function -// Then it should return -Infinity - -// 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 with non-number values -// When passed to the max function -// Then it should return the max and ignore non-numeric values +console.log(findMax(["banana", 3, 20, -5, "apple", 3.5])); +console.log(findMax([10, -5, 20, -3])); // 20 (mixed positive/negative) +console.log(findMax([-10, -5, -3, -8])); // -3 (all negative) +console.log(findMax([1.5, 2.8, 1.2, 3.1])); // 3.1 (decimals) +console.log(findMax([233])); // 233 (single number) +console.log(findMax([])); // -Infinity (empty array) +console.log(findMax(["banana"])); // -Infinity (no valid numbers) -// 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 module.exports = findMax; From c788bfa970e8d866401d78a5b2e0340fa3bb51c2 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 18:49:55 +0100 Subject: [PATCH 08/56] wrote test for all test cases --- Sprint-1/implement/max.test.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 82f18fd88..4f590e28a 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -16,28 +16,49 @@ 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.todo("given an empty array, returns -Infinity"); +test("given an empty array, returns -Infitiny", () => { + expect(findMax([])).toEqual(-Infinity); +}) // Given an array with one number // When passed to the max function // Then it should return that number +test("given an array with one number, returns that number", () => { + expect(findMax([1])).toEqual(1); +}) // Given an array with both positive and negative numbers // When passed to the max function // Then it should return the largest number overall +test("given an array with both positive and negative numbers, return the largest number overall", () => { + expect(findMax([-10, 3, 6, -1])).toEqual(6); +}) // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero +test("given an array with just negative numbers, return the closest one to zero", () => { + expect(findMax([-10, -1, -4, -15])).toEqual(-1); +}) // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number +test("given an array with decimal numbers, return the largest decimal number", () => { + expect(findMax([3.2, 4.9, 6.1, 2.9])).toEqual(6.1); +}) // 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("given an array with non-number values, return the max and ignore non-numeric values", () => { + expect(findMax(["banana", 20, 5, "apple"])).toEqual(20); +}) // 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 +test("given an array with only non-number values, return -Infinity", () => { + expect(findMax(["banana", "apple", "orange"])).toEqual(-Infinity); +}) \ No newline at end of file From 2fc3acf898df5ea59a57a661df033c8982c77d5b Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 19:12:51 +0100 Subject: [PATCH 09/56] wrote code as indicated in the guidelines tested node --- Sprint-1/implement/package.json | 15 +++++++++++++++ Sprint-1/implement/sum.js | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 Sprint-1/implement/package.json diff --git a/Sprint-1/implement/package.json b/Sprint-1/implement/package.json new file mode 100644 index 000000000..ff6f1e295 --- /dev/null +++ b/Sprint-1/implement/package.json @@ -0,0 +1,15 @@ +{ + "name": "implement", + "version": "1.0.0", + "description": "", + "main": "dedupe.js", + "scripts": { + "test": "jest" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "jest": "^30.2.0" + } +} diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..ef1565503 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,23 @@ function sum(elements) { + // filter out only valid numbers from the input array + const onlyNumbers = elements.filter(x => typeof x === "number" && !isNaN(x)); + // empty array + if ( onlyNumbers.length === 0) { + return 0; + // array with only one number + } if ( onlyNumbers.length === 1) { + return onlyNumbers[0]; + } // take first element + sum of the rest untill it's just a number + return onlyNumbers[0] + sum(onlyNumbers.slice(1)); } +console.log(sum([-1, 5, 10, -1])); +console.log(sum(["banana", -1, 5, 10, -1, "pear"])); +console.log(sum([-1, -5, -10, -1])); +console.log(sum([1, 5, 10, 1])); +console.log(sum([])); +console.log(sum([10])); +console.log(sum(["banana"])); +console.log(sum([-1, 5.9, 10.4, -1.2])); + module.exports = sum; From e0ab91c26110fc3c382d5811e474515ff8e4e7df Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 19:18:26 +0100 Subject: [PATCH 10/56] created test cases passed all test cases --- Sprint-1/implement/sum.test.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index dd0a090ca..c59680dc7 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -13,24 +13,40 @@ 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.todo("given an empty array, returns 0") +test("given an empty array, return 0", () => { + expect(sum([])).toEqual(0); +}) // Given an array with just one number // When passed to the sum function // Then it should return that number +test("given an array with just one number, return that number", () => { + expect(sum([5])).toEqual(5); +}) // Given an array containing negative numbers // When passed to the sum function // Then it should still return the correct total sum - +test("given an array containing negative numbers, return the correct total sum", () => { + expect(sum([5, -10])).toEqual(-5); +}) // Given an array with decimal/float numbers // When passed to the sum function // Then it should return the correct total sum +test("given an array with decimal/float numbers, return the correct total sum", () => { + expect(sum([10.1, 10.2, 6.3])).toEqual(26.6); +}) // 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("given an array containing non-number values, return the sum of numerical elements", () => { + expect(sum(["banana", 5, "apple", 10])).toEqual(15); +}) // 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 +test("given an array with only non-number values, return lest surprising value, so 0", () => { + expect(sum(["banana", "apple"])).toEqual(0); +}) From 387af8f973fe71ea67d44ba8078a70c9064057a8 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 19:37:02 +0100 Subject: [PATCH 11/56] rewrote the code using for... of jest test to see if it works --- Sprint-1/refactor/includes.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..adc9b42cb 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,6 +1,18 @@ // Refactor the implementation of includes to use a for...of loop function includes(list, target) { + for (const element of list) { + if (element === target) { + return true; + } + } + return false; +} + + + + +/*function includes(list, target) { for (let index = 0; index < list.length; index++) { const element = list[index]; if (element === target) { @@ -9,5 +21,5 @@ function includes(list, target) { } return false; } - +*/ module.exports = includes; From b1d73dbebb6e8f91ab6361a1bd5e80a8b781bb2b Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 11 Nov 2025 19:40:09 +0100 Subject: [PATCH 12/56] small visual changes, nothing on code --- Sprint-1/refactor/includes.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index adc9b42cb..034cc9a6c 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -9,8 +9,8 @@ function includes(list, target) { return false; } - - +console.log(includes([1, 10, 15, 20], 6)); +module.exports = includes; /*function includes(list, target) { for (let index = 0; index < list.length; index++) { @@ -20,6 +20,4 @@ function includes(list, target) { } } return false; -} -*/ -module.exports = includes; +}*/ \ No newline at end of file From 8c8095c6eb4b9c7574e5902ef5397423fc07e64c Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 12 Nov 2025 12:14:22 +0100 Subject: [PATCH 13/56] wrote code to transform input to array wrote code to find the final frequency wrote code to see where is the first repeated frequency node test --- Sprint-1/stretch/aoc-2018-day1/solution.js | 1026 ++++++++++++++++++++ 1 file changed, 1026 insertions(+) diff --git a/Sprint-1/stretch/aoc-2018-day1/solution.js b/Sprint-1/stretch/aoc-2018-day1/solution.js index e69de29bb..d3efa9a7f 100644 --- a/Sprint-1/stretch/aoc-2018-day1/solution.js +++ b/Sprint-1/stretch/aoc-2018-day1/solution.js @@ -0,0 +1,1026 @@ +const inputString = `+13 ++4 +-8 ++11 ++13 +-12 ++19 ++6 +-4 +-7 ++3 ++16 +-18 ++11 +-10 ++11 ++13 +-4 +-16 ++19 +-1 ++12 +-20 ++17 ++9 ++5 +-1 +-18 +-1 ++5 ++18 ++12 ++16 +-8 +-3 ++16 ++9 ++9 ++6 ++11 +-19 ++6 +-19 +-9 ++5 ++9 ++4 ++17 +-12 +-20 ++9 +-15 +-11 +-2 +-1 +-5 +-12 +-4 +-2 +-7 +-1 ++9 ++3 +-1 ++5 +-1 ++13 ++18 +-17 ++15 +-1 +-6 ++15 ++3 ++9 ++16 ++18 +-3 ++18 +-14 ++17 +-11 ++15 ++14 ++12 ++5 ++9 +-13 ++3 +-15 +-18 +-13 ++17 +-15 ++16 ++9 +-6 +-13 +-10 +-16 +-9 ++4 +-12 +-2 +-9 +-8 ++6 ++12 ++20 +-9 ++8 ++7 ++13 +-11 ++19 ++9 +-13 +-1 +-7 ++6 +-19 +-17 ++12 +-3 +-8 ++17 +-16 ++17 ++1 ++21 ++12 ++4 ++3 ++16 ++19 ++11 ++12 ++15 ++14 ++17 +-5 ++18 ++15 ++15 ++5 ++6 +-16 +-20 ++17 +-10 +-1 ++18 ++17 ++7 ++13 +-8 ++3 ++2 ++2 ++19 +-5 ++11 +-5 ++8 +-5 ++19 ++12 +-2 ++7 ++6 +-16 +-17 ++4 ++9 ++1 +-9 +-8 ++5 +-13 +-12 ++17 +-4 +-12 +-16 ++17 +-8 +-12 +-12 +-8 ++7 ++9 +-7 ++3 ++2 ++4 ++19 +-13 ++12 +-8 ++6 ++13 +-3 ++9 ++15 +-1 ++13 +-3 +-15 ++8 ++19 ++16 ++14 +-18 +-6 ++1 ++11 +-17 +-14 ++3 ++14 ++11 +-20 ++1 +-16 +-9 ++4 ++18 ++16 ++13 +-5 ++14 +-7 +-16 ++15 ++15 ++4 ++5 +-14 ++8 ++17 ++4 ++19 +-3 ++14 ++8 +-1 ++7 +-2 ++1 ++4 +-1 +-1 ++7 ++10 ++13 +-1 +-10 ++5 +-3 +-17 +-17 +-17 ++16 +-7 +-10 +-5 +-19 ++5 +-4 ++6 ++14 +-5 ++19 +-15 ++7 +-14 ++5 ++15 ++10 ++15 ++8 ++3 +-6 +-12 ++17 ++14 +-11 ++7 ++15 +-4 +-16 ++2 ++5 ++17 ++2 +-9 ++5 +-7 ++21 +-15 ++14 ++2 +-12 ++7 ++6 ++16 ++14 +-5 +-8 +-15 ++4 ++15 ++20 ++1 +-15 ++1 ++10 +-14 +-2 +-7 +-11 +-14 +-24 +-16 ++9 +-24 ++3 +-4 +-15 ++14 +-22 +-13 +-17 ++1 +-13 +-6 ++2 ++11 +-19 +-10 ++3 ++12 ++24 +-1 +-13 +-1 ++3 ++19 +-13 ++7 ++16 +-2 ++5 ++14 +-3 ++4 +-24 +-14 ++8 +-3 +-15 +-17 +-16 ++26 +-15 +-17 ++5 ++9 ++52 +-8 +-15 +-13 +-6 +-37 +-14 +-3 +-10 +-1 +-12 +-14 +-8 ++10 ++10 +-5 ++15 +-37 ++9 +-11 +-11 ++12 +-15 ++2 +-8 +-19 +-2 ++19 +-6 +-6 ++16 +-12 ++1 ++19 +-15 ++19 ++2 +-17 +-3 +-13 +-5 +-11 +-17 +-14 ++19 ++2 ++15 +-9 +-18 +-16 +-16 ++5 +-9 ++7 ++16 ++3 +-18 ++4 ++3 +-9 +-14 +-13 +-13 +-16 +-19 ++11 +-1 ++14 ++10 ++17 ++17 +-5 ++16 +-17 +-17 ++11 ++10 ++16 ++11 +-13 ++17 +-10 ++16 +-18 +-15 ++16 +-14 ++18 ++16 ++7 ++12 +-16 ++12 +-10 ++17 +-14 ++8 ++15 +-18 +-18 ++7 ++8 +-17 ++1 +-12 ++16 +-2 ++16 ++13 ++2 +-7 ++10 +-2 +-14 ++20 ++5 ++16 +-13 +-18 ++14 ++19 ++16 +-6 +-8 +-30 ++14 ++26 ++9 ++9 ++20 ++52 +-45 +-165 +-15 ++7 ++2 +-13 +-6 ++16 +-17 +-9 ++1 ++7 ++5 ++11 ++23 +-2 +-7 ++6 +-7 +-4 ++21 +-15 +-5 +-17 +-6 +-42 ++3 ++40 ++18 ++41 ++3 ++13 +-92 +-22 +-17 +-37 +-17 ++10 ++19 +-24 +-10 +-2 +-3 +-1 ++8 ++12 +-17 ++14 ++6 ++19 ++4 +-41 +-64 +-5 +-16 ++5 +-4 +-20 +-7 ++4 ++1 +-15 +-11 +-3 +-13 ++58 ++33 ++8 +-10 +-6 +-69 ++1 +-107 ++84 +-79266 +-8 ++13 ++3 +-18 ++11 ++12 +-17 ++10 ++9 ++15 ++13 ++16 +-11 ++8 ++5 +-6 +-4 +-1 +-10 ++6 +-13 +-7 ++8 +-14 +-17 ++1 ++13 ++4 ++20 +-2 +-4 ++3 +-14 ++3 ++4 +-15 ++3 ++18 +-12 +-16 +-16 +-15 ++11 +-17 +-12 ++13 +-2 ++6 ++5 ++16 +-7 ++4 +-16 +-18 ++8 ++18 +-3 +-8 ++18 +-6 ++11 +-2 +-16 +-16 ++2 +-9 ++16 ++9 +-35 +-19 +-2 +-17 ++4 ++10 ++17 ++12 ++2 +-18 +-3 ++12 ++4 +-12 ++2 +-18 ++6 ++8 ++8 ++8 ++5 +-12 +-14 +-11 ++1 +-16 ++4 +-7 +-10 +-7 +-16 +-15 +-17 ++11 +-12 ++17 +-1 ++18 ++4 ++2 +-12 ++7 +-6 +-3 ++5 ++19 +-2 +-11 +-12 +-10 +-1 +-17 +-15 +-11 +-12 +-7 +-12 +-3 ++11 +-12 +-14 +-3 ++2 ++9 +-2 ++6 ++4 ++19 +-15 +-1 +-15 +-17 +-20 ++9 ++13 ++13 ++20 ++7 +-8 +-8 +-15 +-8 ++15 ++12 +-16 +-15 ++17 +-9 ++1 +-22 +-4 ++11 ++3 +-1 +-17 ++10 ++3 +-4 +-3 +-11 +-17 ++2 ++4 +-18 ++7 ++1 +-9 +-12 +-1 ++3 +-10 +-18 ++1 +-14 ++7 +-10 +-13 +-4 ++13 ++16 +-19 +-2 +-15 +-8 ++1 ++9 ++11 ++1 ++18 +-13 ++18 ++6 ++7 ++10 ++1 ++12 ++17 +-9 ++8 +-14 +-4 +-14 +-11 ++10 +-3 +-8 +-16 ++20 ++10 ++4 ++6 ++1 ++13 ++11 +-10 +-8 ++20 ++14 +-6 ++10 +-11 ++2 +-6 +-19 ++15 +-10 +-13 +-10 +-10 +-10 ++2 +-5 +-6 +-3 +-18 ++11 +-7 +-17 +-18 +-8 ++13 ++2 ++18 ++25 +-9 ++16 +-10 +-10 +-14 +-1 ++18 ++14 ++12 ++27 +-10 ++3 +-12 +-30 ++23 ++6 ++44 ++13 +-19 +-15 ++5 ++18 ++9 +-7 ++5 +-6 ++17 ++15 +-21 ++4 ++13 +-23 ++21 ++12 +-19 ++5 ++16 ++32 ++8 ++8 ++15 +-6 ++11 +-14 ++17 ++4 ++2 ++4 ++3 ++8 ++13 +-14 ++13 +-6 +-18 +-18 +-15 ++13 +-2 +-17 ++4 +-15 ++20 ++5 ++15 +-9 +-9 +-14 ++5 ++8 +-2 ++10 ++20 ++10 +-15 +-8 +-20 ++18 ++12 ++19 ++1 +-9 ++19 +-12 ++18 ++9 ++8 ++10 ++3 ++13 +-5 +-3 ++14 +-9 +-12 +-4 +-12 ++8 +-15 ++21 +-11 ++1 ++17 ++17 +-18 ++4 ++20 ++11 +-12 ++21 +-4 ++14 +-16 +-7 ++6 +-15 +-6 +-7 +-7 +-16 ++7 ++20 ++8 ++9 ++18 ++8 ++17 +-6 +-3 +-12 ++9 ++10 +-12 ++9 +-21 +-19 +-29 +-12 ++33 +-8 +-7 +-41 ++7 ++11 +-33 +-10 ++7 ++17 +-19 +-15 ++5 +-6 +-19 ++16 +-4 +-30 +-19 ++1 ++14 +-28 +-12 ++23 +-67 ++48 +-110 +-18 +-12 ++2 +-7 +-12 +-12 +-8 ++80339`; + + +// transform input to array +const changes = inputString + .split('\n') + .filter(line =>line.trim()) + .map(Number); + +//Calculate total frequency +const part1Result = changes.reduce((sum, change) => sum + change, 0); +console.log(`Part 1 - Resulting frequency: ${part1Result}`); +function findRepeatingFrequency(changes) { + let currentFrequency = 0; + const seen = new Set ([0]); + + while (true) { + for ( const change of changes) { + currentFrequency += change; + if (seen.has(currentFrequency)) { + return currentFrequency; + } + seen.add(currentFrequency) + } + } +} +const part2Result = findRepeatingFrequency (changes); +console.log(`Part 2 - First repeating frequency: ${part2Result}`); From 8af33c9c73119e55475ea83ff83225ddaa691b3c Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 12 Nov 2025 17:25:25 +0100 Subject: [PATCH 14/56] wrote the code to both exercises node test --- Sprint-2/debug/address.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 940a6af83..811d43258 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,5 +1,7 @@ // Predict and explain first... + // I think it will show a syntax error due to inside const address we have more data than just the house number as requested. + // This code should log out the houseNumber from the address object // but it isn't working... // Fix anything that isn't working From 80b688b212f8698b64107d851ef4e9595349eb19 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 12 Nov 2025 17:35:15 +0100 Subject: [PATCH 15/56] added package.json --- Sprint-1/refactor/package.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Sprint-1/refactor/package.json diff --git a/Sprint-1/refactor/package.json b/Sprint-1/refactor/package.json new file mode 100644 index 000000000..a4b346ee3 --- /dev/null +++ b/Sprint-1/refactor/package.json @@ -0,0 +1,15 @@ +{ + "name": "refactor", + "version": "1.0.0", + "description": "", + "main": "includes.js", + "scripts": { + "test": "jest" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "jest": "^30.2.0" + } +} From a53cf7068261d58533de5030895c293f7fc469be Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 12 Nov 2025 17:40:00 +0100 Subject: [PATCH 16/56] wrote my prevision of what will happen before correcting the code --- Sprint-2/debug/address.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 811d43258..cb3ea2b64 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,7 +1,7 @@ // Predict and explain first... // I think it will show a syntax error due to inside const address we have more data than just the house number as requested. - + // This code should log out the houseNumber from the address object // but it isn't working... // Fix anything that isn't working From c3ee6b9f623c032501a3c074bba86462b02cd23e Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 12 Nov 2025 17:49:47 +0100 Subject: [PATCH 17/56] corrected the code in order to work --- Sprint-2/debug/address.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index cb3ea2b64..5bdb63b6a 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,17 +1,18 @@ // Predict and explain first... // I think it will show a syntax error due to inside const address we have more data than just the house number as requested. + // My house number is undefined - not a syntax // This code should log out the houseNumber from the address object // but it isn't working... // Fix anything that isn't working -const address = { - houseNumber: 42, - street: "Imaginary Road", - city: "Manchester", - country: "England", - postcode: "XYZ 123", -}; +const address = [ + houseNumber = 42, + street = "Imaginary Road", + city = "Manchester", + country = "England", + postcode = "XYZ 123", +]; console.log(`My house number is ${address[0]}`); From c1c4007c6cae7e20469ef002dbb6635604a02ebc Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 12 Nov 2025 17:52:36 +0100 Subject: [PATCH 18/56] When fixing the code to make it work, changed the {} for [] . After checking other possibilites online realized that I could just change the call in console.log left comments explaining what I did and what could have done --- Sprint-2/debug/address.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 5bdb63b6a..b4965100f 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -8,7 +8,7 @@ // Fix anything that isn't working const address = [ - houseNumber = 42, + houseNumber = 56, street = "Imaginary Road", city = "Manchester", country = "England", @@ -16,3 +16,4 @@ const address = [ ]; console.log(`My house number is ${address[0]}`); + From 6e8d07f3547c371b14e82c47fe58c09e9b2b98a8 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 12 Nov 2025 17:55:49 +0100 Subject: [PATCH 19/56] console.log all options --- Sprint-2/debug/address.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index b4965100f..3c23476cb 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -14,6 +14,13 @@ const address = [ country = "England", postcode = "XYZ 123", ]; +// changed from {} to [] and from : to = +// could just change the call in console.log with the original code +// with this code, to console.log, I have to call by the index 0,1,2,3,4,5 console.log(`My house number is ${address[0]}`); +console.log(`My street name is ${address[1]}`); +console.log(`My city is ${address[2]}`); +console.log(`My country is ${address[3]}`); +console.log(`My postcode is ${address[4]}`); From 71e3a4192e97ffe2533492a890414b9c8a5c591e Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 13 Nov 2025 10:47:33 +0100 Subject: [PATCH 20/56] predicted what is going to happen and why --- Sprint-2/debug/author.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 8c2125977..fe99c36f0 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,5 +1,5 @@ // Predict and explain first... - + // I believe is not working because is not an array // This program attempts to log out all the property values in the object. // But it isn't working. Explain why first and then fix the problem From d86785fd4820c93f7ff6c3717d098ea84b87c2aa Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 13 Nov 2025 10:56:09 +0100 Subject: [PATCH 21/56] -Fixed the original code and left comments what was wrong and what I did to fix it --- Sprint-2/debug/author.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index fe99c36f0..ae4ae5a53 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,5 +1,8 @@ // Predict and explain first... - // I believe is not working because is not an array + + // I believe is not working because is not an array, it will give me an syntax error + // real error: TypeError: author is not iterable + // This program attempts to log out all the property values in the object. // But it isn't working. Explain why first and then fix the problem @@ -11,6 +14,7 @@ const author = { alive: true, }; -for (const value of author) { - console.log(value); +for (const value of Object.keys(author)) { + const info = author[value]; + console.log(value, info); } From 193f8bfb360f6d3fd4cb268653545a55ed98a5b8 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 13 Nov 2025 11:09:27 +0100 Subject: [PATCH 22/56] Predicted the issue and explained why --- Sprint-2/debug/author.js | 2 ++ Sprint-2/debug/recipe.js | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index ae4ae5a53..1a58d6847 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -14,6 +14,8 @@ const author = { alive: true, }; +// used Object.keys in order to iterate over the properties or entries of an object; +// “Give me all the keys from the author object, then for each one, show me the key and its value.” for (const value of Object.keys(author)) { const info = author[value]; console.log(value, info); diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cd..69812a3b0 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,5 +1,8 @@ // Predict and explain first... + // Is missing the instruction to log the ingredients in different lines, so it will not show the ingredients + // and also not in a different line + // This program should log out the title, how many it serves and the ingredients. // Each ingredient should be logged on a new line // How can you fix it? @@ -10,6 +13,6 @@ const recipe = { ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title} serves ${recipe.serves} - ingredients: -${recipe}`); +console.log(`${recipe.title} serves ${recipe.serves} + ingredients: + ${recipe}`); From 5d002d5630d4c8d70d32ec2e7a5d8df33c3fbd63 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 13 Nov 2025 11:21:55 +0100 Subject: [PATCH 23/56] - fixed code in order to follow the exercise guidelines - left comments explaining --- Sprint-2/debug/recipe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 69812a3b0..c3e46892a 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -15,4 +15,4 @@ const recipe = { console.log(`${recipe.title} serves ${recipe.serves} ingredients: - ${recipe}`); + ${recipe.ingredients.join('\n')}`); // .join('\n') to make a new line for each value on the string From 2e54027fd964641cadb1fb2117c4862a63d036fe Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 13 Nov 2025 11:54:15 +0100 Subject: [PATCH 24/56] - implemented function that checks if an object contains a particular property - node test --- Sprint-2/implement/contains.js | 33 ++++++++++++++++++++++++++++- Sprint-2/implement/contains.test.js | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a..cc27850a8 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,34 @@ -function contains() {} +function contains(obj, prop) { // define parameters + if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) { + return false; + } + return Object.prototype.hasOwnProperty.call(obj, prop); +} + + +// Given a contains function +// When passed an object and a property name +// Then it should return true if the object contains the property, false otherwise +console.log(contains({a: 1, b: 2}, 'a')); // true + +// Given an empty object +// When passed to contains +// Then it should return false +console.log(contains({}, 'a')); // false + +// Given an object with properties +// When passed to contains with an existing property name +// Then it should return true +console.log(contains({a: 1, b: 2}, 'a')); // true + +// Given an object with properties +// When passed to contains with a non-existent property name +// Then it should return false +console.log(contains({a: 1, b: 2}, 'c')); // false + +// Given invalid parameters like an array +// When passed to contains +// Then it should return false or throw an error +console.log(contains([], 'a')); // false module.exports = contains; diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 326bdb1f2..8f6ed8a87 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -20,7 +20,7 @@ as the object doesn't contains a key of 'c' // Given an empty object // When passed to contains // Then it should return false -test.todo("contains on empty object returns false"); +//test.todo("contains on empty object returns false"); // Given an object with properties // When passed to contains with an existing property name From 45cff676f76021a91d03282eb5f11b506417202b Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 13 Nov 2025 13:17:26 +0100 Subject: [PATCH 25/56] installed json to run tests --- Sprint-2/implement/contains.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 8f6ed8a87..aca72c602 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -16,6 +16,9 @@ as the object doesn't contains a key of 'c' // Given a contains function // When passed an object and a property name // Then it should return true if the object contains the property, false otherwise +test("object contains property", () => { + expect(contains({a: 1, b: 2}, 'a')).toEqual(true); +}) // Given an empty object // When passed to contains From 7af131622daf3d21afdfc254c34b71e4f224eac7 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 13 Nov 2025 13:25:28 +0100 Subject: [PATCH 26/56] wrote test cases for all accepted criteria tested and corrected issues --- Sprint-2/implement/contains.test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index aca72c602..036e800f2 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -23,16 +23,27 @@ test("object contains property", () => { // Given an empty object // When passed to contains // Then it should return false -//test.todo("contains on empty object returns false"); +test("empty object", () => { + expect(contains({}, 'a')).toEqual(false); +}) // Given an object with properties // When passed to contains with an existing property name // Then it should return true +test("object contains existing property", () => { + expect(contains({a: 1, b: 2}, 'a')).toEqual(true); +}) // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false +test("object does not contain property", () => { + expect(contains({a: 1, b: 2}, 'c')).toEqual(false); +}) // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error +test("invalid parameters", () => { + expect(contains([], 'a')).toEqual(false); +}) From 9783c03549a4a86cc5b16fd018ea2e0ae7a74ece Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 13 Nov 2025 14:07:27 +0100 Subject: [PATCH 27/56] wrote function according to guidelines node test to check if work --- Sprint-2/implement/lookup.js | 10 ++++++++-- Sprint-2/implement/package.json | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 Sprint-2/implement/package.json diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index a6746e07f..0499dd3ec 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,5 +1,11 @@ -function createLookup() { - // implementation here +function createLookup(countryCurrencyPairs) { + const lookup = {}; + + for (const [country, currency] of countryCurrencyPairs) { + lookup[country] = currency; + } + return lookup; } +console.log(createLookup([['PT', 'EUR'], ['CA', 'CAD']])); module.exports = createLookup; diff --git a/Sprint-2/implement/package.json b/Sprint-2/implement/package.json new file mode 100644 index 000000000..df5c00c2b --- /dev/null +++ b/Sprint-2/implement/package.json @@ -0,0 +1,15 @@ +{ + "name": "implement", + "version": "1.0.0", + "description": "", + "main": "contains.js", + "scripts": { + "test": "jest" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "jest": "^30.2.0" + } +} From 6fd918633a57fecfac50e6b03c9f102b11e54750 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 13 Nov 2025 14:15:14 +0100 Subject: [PATCH 28/56] wrote test case --- Sprint-2/implement/lookup.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 547e06c5a..ccee22e0a 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -2,6 +2,13 @@ const createLookup = require("./lookup.js"); test.todo("creates a country currency code lookup for multiple codes"); +test("creates lookup object from country-currency pairs", () => { + const input = [['US', 'USD'], ['CA', 'CAD']]; + const expected = { US: 'USD', CA: 'CAD' }; + + expect(createLookup(input)).toEqual(expected); +}); + /* Create a lookup object of key value pairs from an array of code pairs From e4f7ebdfcaae3e6e65192132b70905b5012d4ca9 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 18 Nov 2025 10:55:18 +0100 Subject: [PATCH 29/56] - Fixed the code with the help of reading materials and Ai - node test --- Sprint-2/implement/querystring.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 45ec4e5f3..a6eebc12c 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -1,16 +1,31 @@ function parseQueryString(queryString) { const queryParams = {}; - if (queryString.length === 0) { - return queryParams; + + if (!queryString) return queryParams; +// remove leading "?" + if (queryString.startsWith("?")) { + queryString = queryString.slice(1); } + const keyValuePairs = queryString.split("&"); for (const pair of keyValuePairs) { - const [key, value] = pair.split("="); - queryParams[key] = value; + if (!pair) continue; + + const [key, ...rest] = pair.split("="); + const value = rest.join("=") // handles "=" inside values + + const decodedKey = decodeURIComponent(key); // used to make the URL readable. e.g.: from { name: "John%20Doe" } to { name: "John Doe" } + const decodedValue = value ? decodeURIComponent(value) : ""; + + queryParams[decodedKey] = decodedValue; } return queryParams; } +console.log(parseQueryString("name=oliveira&age=28")); +console.log(parseQueryString("name=Beatriz%20Oliveira&city=Brussels")); + + module.exports = parseQueryString; From 1dbd8cdee3fbb3f17a08b9e7ccb4a83e8dfb25c5 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 18 Nov 2025 11:02:00 +0100 Subject: [PATCH 30/56] - tested the original code to check if working; - wrote new test; --- Sprint-2/implement/querystring.js | 4 ++-- Sprint-2/implement/querystring.test.js | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index a6eebc12c..e7de1bf7b 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -24,8 +24,8 @@ function parseQueryString(queryString) { return queryParams; } -console.log(parseQueryString("name=oliveira&age=28")); -console.log(parseQueryString("name=Beatriz%20Oliveira&city=Brussels")); +//console.log(parseQueryString("name=oliveira&age=28")); +//console.log(parseQueryString("name=Beatriz%20Oliveira&city=Brussels")); module.exports = parseQueryString; diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 3e218b789..ecfac0853 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -6,7 +6,9 @@ const parseQueryString = require("./querystring.js") test("parses querystring values containing =", () => { - expect(parseQueryString("equation=x=y+1")).toEqual({ - "equation": "x=y+1", - }); + expect(parseQueryString("equation=x=y+1")).toEqual({"equation": "x=y+1",}); }); + +test("parses querystring values containing %20", () => { + expect(parseQueryString("name=Beatriz%20Oliveira&city=Brussels")).toEqual({name: 'Beatriz Oliveira', city: 'Brussels'}); +}); \ No newline at end of file From 0c5b96ac4b14eeaef544774661d78b7cd4cdc70a Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 18 Nov 2025 11:21:13 +0100 Subject: [PATCH 31/56] Code to check if it's an array Code to deal with empty arrays --- Sprint-2/implement/tally.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index f47321812..aa7e7ff34 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,3 +1,25 @@ -function tally() {} +function tally(arr) { + if (!Array.isArray(arr)) { + return "THIS IS NOT AN ARRAY!"; + } + if (arr.length === 0) { + return []; + } +} +console.log(tally([])); + +// Acceptance criteria: + +// Given a function called tally +// When passed an array of items +// Then it should return an object containing the count for each unique item + + + +// Given an array with duplicate items +// When passed to tally +// Then it should return counts for each unique item + + module.exports = tally; From 5ea87b74a5aaa478a1e150f075dbc83edbd31cf3 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 18 Nov 2025 11:35:38 +0100 Subject: [PATCH 32/56] code for duplicate items node test to check --- Sprint-2/implement/tally.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index aa7e7ff34..40f8e4827 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -5,8 +5,22 @@ function tally(arr) { if (arr.length === 0) { return []; } + + const result = {}; + + for (const item of arr) { + if (result[item] === undefined) { + result [item] = 1; + } else { + result[item] = result[item] + 1; + } + } + return result; } + +console.log(tally("dasda")); console.log(tally([])); +console.log(tally(["a", "b", "c", "b", "a", "a"])); // Acceptance criteria: From 8b4e48fc21ca97ddef8baa836039f2710a32bcd4 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 18 Nov 2025 14:07:05 +0100 Subject: [PATCH 33/56] update the return of an empty array from [] to {} --- Sprint-2/implement/tally.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 40f8e4827..9295cda7d 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -3,9 +3,11 @@ function tally(arr) { return "THIS IS NOT AN ARRAY!"; } if (arr.length === 0) { - return []; + return {}; } - + /* ANOTHER WAY OF DOING THE DUPLICATE ITEMS +result[item] = (result[item] || 0) + 1; + */ const result = {}; for (const item of arr) { @@ -22,18 +24,5 @@ console.log(tally("dasda")); console.log(tally([])); console.log(tally(["a", "b", "c", "b", "a", "a"])); -// Acceptance criteria: - -// Given a function called tally -// When passed an array of items -// Then it should return an object containing the count for each unique item - - - -// Given an array with duplicate items -// When passed to tally -// Then it should return counts for each unique item - - module.exports = tally; From d3f9f6132f65678666c53f53a1dd2a1fbda30eab Mon Sep 17 00:00:00 2001 From: Pirikita Date: Tue, 18 Nov 2025 14:19:53 +0100 Subject: [PATCH 34/56] created tests for every test case tested if working --- Sprint-2/implement/tally.js | 6 +++--- Sprint-2/implement/tally.test.js | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 9295cda7d..4b891fab0 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -20,9 +20,9 @@ result[item] = (result[item] || 0) + 1; return result; } -console.log(tally("dasda")); -console.log(tally([])); -console.log(tally(["a", "b", "c", "b", "a", "a"])); +//console.log(tally("dasda")); +//console.log(tally([])); +//console.log(tally(["a", "b", "c", "b", "a", "a"])); module.exports = tally; diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 2ceffa8dd..6605552d4 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -19,16 +19,28 @@ const tally = require("./tally.js"); // Given a function called tally // When passed an array of items // Then it should return an object containing the count for each unique item +test("tally on an array of items returns the count for each unique item", () => { + expect(tally(['a', 'a', 'b', 'c'])).toEqual({ a : 2, b: 1, c: 1 }); +}) // Given an empty array // When passed to tally // Then it should return an empty object -test.todo("tally on an empty array returns an empty object"); - +//test.todo("tally on an empty array returns an empty object"); +test("tally on an empty array returns an empty object", () => { + expect(tally([])).toEqual({}); +}) // Given an array with duplicate items // When passed to tally // Then it should return counts for each unique item +test("tally on an array with duplicate items", () => { + expect(tally(['a', 'a', 'b', 'c'])).toEqual({ a : 2, b: 1, c: 1 }); +}) + // Given an invalid input like a string // When passed to tally // Then it should throw an error +test("tally on an invalid input returns an error", () => { + expect(tally("fasdas")).toEqual("THIS IS NOT AN ARRAY!"); +}) From e90d5de267602d3e9bcf8c2769f192e15df30823 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 19 Nov 2025 11:05:35 +0100 Subject: [PATCH 35/56] answer all the questions before fixing the code --- Sprint-2/interpret/invert.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index bb353fb1f..c47b17319 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -10,20 +10,27 @@ function invert(obj) { const invertedObj = {}; for (const [key, value] of Object.entries(obj)) { - invertedObj.key = value; + invertedObj.key = [value]; } return invertedObj; } +console.log(invert({ a: 1, b: 2 })); + // a) What is the current return value when invert is called with { a : 1 } + // { key: [ 1 ] } // b) What is the current return value when invert is called with { a: 1, b: 2 } + // { key: [ 2 ] } // c) What is the target return value when invert is called with {a : 1, b: 2} + // {1: a, 2: b} // c) What does Object.entries return? Why is it needed in this program? + // returns an array of key-value pairs // d) Explain why the current return value is different from the target output + // because we are only inverting the value and not the key and it's also overwriting the first object // e) Fix the implementation of invert (and write tests to prove it's fixed!) From b3f840e4a38dd486da9e888d9cbf42c007b8f3eb Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 19 Nov 2025 11:09:58 +0100 Subject: [PATCH 36/56] fixed the code on line 13 node test to check if its working --- Sprint-2/interpret/invert.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index c47b17319..edf2cf83f 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -10,13 +10,14 @@ function invert(obj) { const invertedObj = {}; for (const [key, value] of Object.entries(obj)) { - invertedObj.key = [value]; + invertedObj[value] = key; // use the original value as the new key and the original key as the new value } return invertedObj; } console.log(invert({ a: 1, b: 2 })); +console.log(invert({x : 10, y : 20})); // a) What is the current return value when invert is called with { a : 1 } // { key: [ 1 ] } From 45286cff25f385a6b21aae57c1506f6bb64bafb4 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 19 Nov 2025 11:14:23 +0100 Subject: [PATCH 37/56] prepared doc for export to do test --- Sprint-2/interpret/invert.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index edf2cf83f..c28d93f80 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -19,6 +19,8 @@ function invert(obj) { console.log(invert({ a: 1, b: 2 })); console.log(invert({x : 10, y : 20})); +module.export = invert; + // a) What is the current return value when invert is called with { a : 1 } // { key: [ 1 ] } From c69cc000f384c0e832ed34bf9122a7054efd9d5d Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 19 Nov 2025 11:53:23 +0100 Subject: [PATCH 38/56] update the export installed dependencies installed package --- Sprint-2/interpret/invert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index c28d93f80..c0f74ea23 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -19,7 +19,7 @@ function invert(obj) { console.log(invert({ a: 1, b: 2 })); console.log(invert({x : 10, y : 20})); -module.export = invert; +module.exports = invert; // a) What is the current return value when invert is called with { a : 1 } // { key: [ 1 ] } From 156964dfc743546b5be4116fbe0c36a3b8972dc1 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 19 Nov 2025 12:13:21 +0100 Subject: [PATCH 39/56] wrote test case for simple key-values, mixed types, empty objects and single key-value pair --- Sprint-2/interpret/invert.test.js | 17 +++++++++++++++++ Sprint-2/interpret/package.json | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Sprint-2/interpret/invert.test.js create mode 100644 Sprint-2/interpret/package.json diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js new file mode 100644 index 000000000..5554c0d56 --- /dev/null +++ b/Sprint-2/interpret/invert.test.js @@ -0,0 +1,17 @@ +const invert = require ('./invert.js'); + +test("should invert simple key values", () => { + expect(invert({ a: 1, b: 2 })).toEqual({ '1': 'a', '2': 'b' }); +}) + +test("should invert mixed types", () =>{ + expect(invert({ name: 'John', age: 30 })).toEqual({ 'John': 'name', '30': 'age' }); +}) + +test("should return empty object when given an empty object", () => { + expect(invert({})).toEqual({}); +}) + +test("should invert single key-value pair", () =>{ + expect(invert({ a: 1 })).toEqual({ '1': 'a' }); +}) \ No newline at end of file diff --git a/Sprint-2/interpret/package.json b/Sprint-2/interpret/package.json new file mode 100644 index 000000000..6cb72b3a4 --- /dev/null +++ b/Sprint-2/interpret/package.json @@ -0,0 +1,15 @@ +{ + "name": "interpret", + "version": "1.0.0", + "description": "", + "main": "invert.js", + "scripts": { + "test": "jest" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "jest": "^30.2.0" + } +} From ba6748a6e149ac2382dc74ebf6ee5876f2bbd06c Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 19 Nov 2025 12:51:47 +0100 Subject: [PATCH 40/56] created working function with the exercise basic request node test --- Sprint-2/stretch/count-words.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sprint-2/stretch/count-words.js b/Sprint-2/stretch/count-words.js index 8e85d19d7..ccab07788 100644 --- a/Sprint-2/stretch/count-words.js +++ b/Sprint-2/stretch/count-words.js @@ -26,3 +26,24 @@ 3. Order the results to find out which word is the most common in the input */ + +function countWords(string) { + const totalWords = {}; + if (string.length === 0) { + return {}; + } + const words = string.split(' '); + + for(let i=0; i < words.length; i++){ + const word = words[i]; + + if (totalWords[word]) { + totalWords[word] += 1; + } else { + totalWords[word] = 1; + } + } + return totalWords; +} + +console.log(countWords("you and me and you")); \ No newline at end of file From 91865cc64da3c013ba818c15d2aef470a92fa2cb Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 19 Nov 2025 13:18:30 +0100 Subject: [PATCH 41/56] finished code and implemented code for advanced challenges --- Sprint-2/stretch/count-words.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Sprint-2/stretch/count-words.js b/Sprint-2/stretch/count-words.js index ccab07788..7c909d212 100644 --- a/Sprint-2/stretch/count-words.js +++ b/Sprint-2/stretch/count-words.js @@ -32,7 +32,12 @@ function countWords(string) { if (string.length === 0) { return {}; } - const words = string.split(' '); + + const cleanedString = string + .replace(/[.,!?]/g, '') + .toLowerCase(); + + const words = cleanedString.split(' ').filter(word => word.length > 0); for(let i=0; i < words.length; i++){ const word = words[i]; @@ -43,7 +48,16 @@ function countWords(string) { totalWords[word] = 1; } } - return totalWords; + const sortedWords = Object.entries(totalWords) + .sort((a,b) => b[1] - a[1]) + .reduce((sortedObj, [word, count]) => { + sortedObj[word] = count; + return sortedObj; + }, {}); + return sortedWords; } -console.log(countWords("you and me and you")); \ No newline at end of file +console.log(countWords("you and me and you")); +console.log(countWords("you and me and me and you and your friend Steve")); +console.log(countWords("")); +console.log(countWords("A a B b A")); From d7401d2beed6aa1f7d9a48d98c182d18cc5f509b Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 19 Nov 2025 15:06:28 +0100 Subject: [PATCH 42/56] with help of reading materials and AI, understood the function and re wrote it as requested in the exercise --- Sprint-2/stretch/mode.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Sprint-2/stretch/mode.js b/Sprint-2/stretch/mode.js index 3f7609d79..251ca48e3 100644 --- a/Sprint-2/stretch/mode.js +++ b/Sprint-2/stretch/mode.js @@ -9,28 +9,38 @@ // into smaller functions using the stages above function calculateMode(list) { - // track frequency of each value + if (!Array.isArray(list)) { + return NaN; + } + const freqs = countFrequencies(list); + const mode = findMaxFrequency(freqs); + return mode; +} + +function countFrequencies(list) { let freqs = new Map(); - for (let num of list) { - if (typeof num !== "number") { + for(let num of list) { + if(typeof num !== "number") { continue; } - freqs.set(num, (freqs.get(num) || 0) + 1); } + return freqs; +} - // Find the value with the highest frequency +function findMaxFrequency(freqs) { let maxFreq = 0; let mode; + for (let [num, freq] of freqs) { if (freq > maxFreq) { mode = num; maxFreq = freq; } } - return maxFreq === 0 ? NaN : mode; } + module.exports = calculateMode; From a49428d5fc2c063385dc39af4d49d4493d409c9b Mon Sep 17 00:00:00 2001 From: Pirikita Date: Wed, 19 Nov 2025 15:13:07 +0100 Subject: [PATCH 43/56] node test 5 different inputs to check workability --- Sprint-2/stretch/mode.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-2/stretch/mode.js b/Sprint-2/stretch/mode.js index 251ca48e3..36ea9e3c2 100644 --- a/Sprint-2/stretch/mode.js +++ b/Sprint-2/stretch/mode.js @@ -41,6 +41,10 @@ function findMaxFrequency(freqs) { } return maxFreq === 0 ? NaN : mode; } - +console.log(calculateMode([1, 2, 2, 3, 3, 3])); +console.log(calculateMode("hello world")); +console.log(calculateMode([])); +console.log(calculateMode(["a", "b", "c"])); +console.log(calculateMode([1, 3, 5, "a", "b", "c"])); module.exports = calculateMode; From 02c9fa613e9e6d9fd1de39ba7f6cb0f316b07a75 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 20 Nov 2025 10:40:29 +0100 Subject: [PATCH 44/56] answer all the questions before fixing the code --- Sprint-2/stretch/till.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/stretch/till.js b/Sprint-2/stretch/till.js index 6a08532e7..d479e8abe 100644 --- a/Sprint-2/stretch/till.js +++ b/Sprint-2/stretch/till.js @@ -22,10 +22,15 @@ const till = { }; const totalAmount = totalTill(till); +console.log(totalTill(5, 5)); + // a) What is the target output when totalTill is called with the till object + // it should return £4.40 - so it counts the total in pence and then converts to pounds // b) Why do we need to use Object.entries inside the for...of loop in this function? + // used to get key and values as an array so we can iterate over them in the for..of loop // c) What does coin * quantity evaluate to inside the for...of loop? + // is multiplying the coins by quantity so we can have the total amount // d) Write a test for this function to check it works and then fix the implementation of totalTill From 233408f3e31a2892b1f31e1b70515c1c6be20b45 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 20 Nov 2025 10:42:39 +0100 Subject: [PATCH 45/56] created file for tests prepared files for test --- Sprint-2/stretch/till.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/stretch/till.js b/Sprint-2/stretch/till.js index d479e8abe..15409a665 100644 --- a/Sprint-2/stretch/till.js +++ b/Sprint-2/stretch/till.js @@ -24,6 +24,8 @@ const totalAmount = totalTill(till); console.log(totalTill(5, 5)); +module.exports = totalTill; + // a) What is the target output when totalTill is called with the till object // it should return £4.40 - so it counts the total in pence and then converts to pounds From c2710219390268028bae5a0bc68f266989607336 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 20 Nov 2025 10:56:24 +0100 Subject: [PATCH 46/56] fixed the code with help of reading materials and AI --- Sprint-2/stretch/till.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-2/stretch/till.js b/Sprint-2/stretch/till.js index 15409a665..9dee31483 100644 --- a/Sprint-2/stretch/till.js +++ b/Sprint-2/stretch/till.js @@ -8,10 +8,11 @@ function totalTill(till) { let total = 0; for (const [coin, quantity] of Object.entries(till)) { - total += coin * quantity; + const coinValue = parseInt(coin.replace('p', '')); + total += coinValue * quantity; } - return `£${total / 100}`; + return `£${(total / 100).toFixed(2)}`; } const till = { @@ -22,7 +23,7 @@ const till = { }; const totalAmount = totalTill(till); -console.log(totalTill(5, 5)); +console.log(totalAmount); module.exports = totalTill; From 371c1e0088a6a3ea65dfbd0cf1091d7a7f0d330a Mon Sep 17 00:00:00 2001 From: Pirikita Date: Thu, 20 Nov 2025 11:14:20 +0100 Subject: [PATCH 47/56] wrote case tests tested and fixed until working --- Sprint-2/stretch/till.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Sprint-2/stretch/till.test.js diff --git a/Sprint-2/stretch/till.test.js b/Sprint-2/stretch/till.test.js new file mode 100644 index 000000000..50050ad97 --- /dev/null +++ b/Sprint-2/stretch/till.test.js @@ -0,0 +1,21 @@ +const totalTill = require("./till"); + +test("calculates total for original till object", () => { + const till = {"1p": 10, "5p": 6, "50p": 4, "20p": 10}; + expect(totalTill(till)).toEqual("£4.40"); +}); + +test("calculates total for single coin type", () => { + const till = {"1p": 100}; + expect(totalTill(till)).toEqual("£1.00"); +}); + +test("calculates total for mixed coins", () => { + const till = {"50p": 2, "10p": 5}; + expect(totalTill(till)).toEqual("£1.50"); +}); + +test("handles empty till", () => { + const till = {}; + expect(totalTill(till)).toEqual("£0.00"); +}); \ No newline at end of file From 9f73f51defc641bc3e4fe4bad00d68661b3e6c59 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Fri, 28 Nov 2025 16:58:29 +0100 Subject: [PATCH 48/56] implemented function to delete all completed tasks --- Sprint-3/todo-list/index.html | 4 +++- Sprint-3/todo-list/script.mjs | 11 ++++++++++- Sprint-3/todo-list/todos.mjs | 5 +---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 4d12c4654..6f7642a6e 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -34,7 +34,9 @@

My ToDo List

- +
+ +
diff --git a/Sprint-3/todo-list/script.mjs b/Sprint-3/todo-list/script.mjs index ba0b2ceae..c55f5398b 100644 --- a/Sprint-3/todo-list/script.mjs +++ b/Sprint-3/todo-list/script.mjs @@ -45,7 +45,16 @@ function render() { }); } - + // Delete completed tasks button + document.getElementById("delete-completed-btn").addEventListener("click", () => { + // Keep only tasks that are NOT completed + for (let i = todos.length - 1; i >= 0; i--) { + if (todos[i].completed) { + Todos.deleteTask(todos, i); // call your module function + } + } + render(); + }); // Note: // - First child of #todo-item-template is a
  • element. // We will create each ToDo list item as a clone of this node. diff --git a/Sprint-3/todo-list/todos.mjs b/Sprint-3/todo-list/todos.mjs index f17ab6a25..478490e2a 100644 --- a/Sprint-3/todo-list/todos.mjs +++ b/Sprint-3/todo-list/todos.mjs @@ -1,12 +1,9 @@ -/* - A ToDo List (todos) is expected to be represented as an array of objects in +/* A ToDo List (todos) is expected to be represented as an array of objects in the following manner: - [ { task: "Description of task 1", completed: false}, { task: "Description of task 2", completed: true} ] - */ // Append a new task to todos[] From ce74ca4d3ec4a7c1efe82da7d1f8601dcb4d2fe5 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Sun, 7 Dec 2025 17:25:18 +0100 Subject: [PATCH 49/56] changed the appeared of some features --- Sprint-3/alarmclock/index.html | 4 ++-- Sprint-3/alarmclock/style.css | 11 +++++++++++ Sprint-3/todo-list/package.json | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..fd3d596b5 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Timer
    @@ -17,4 +17,4 @@

    Time Remaining: 00:00

    - + diff --git a/Sprint-3/alarmclock/style.css b/Sprint-3/alarmclock/style.css index 0c72de38b..6c017fb8c 100644 --- a/Sprint-3/alarmclock/style.css +++ b/Sprint-3/alarmclock/style.css @@ -1,9 +1,17 @@ +body { + background-color: dimgray; +} + .centre { position: fixed; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); + background-color: grey; + padding: 10%; + border-radius: 25%; + border-style: dashed; } #alarmSet { @@ -12,4 +20,7 @@ h1 { text-align: center; + color:antiquewhite; + font-family: monospace; + font-size: 3em; } diff --git a/Sprint-3/todo-list/package.json b/Sprint-3/todo-list/package.json index ce181158a..36e5bbc1f 100644 --- a/Sprint-3/todo-list/package.json +++ b/Sprint-3/todo-list/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "serve": "http-server", - "test": "NODE_OPTIONS=--experimental-vm-modules jest" + "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest todos.test.mjs" }, "repository": { "type": "git", @@ -17,6 +17,7 @@ }, "homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme", "devDependencies": { + "cross-env": "^10.1.0", "http-server": "^14.1.1", "jest": "^30.0.4" } From 71d23ba5704efb21905b64940e1f1d66f9e9e916 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Sun, 7 Dec 2025 18:15:16 +0100 Subject: [PATCH 50/56] created code for alarmclock app. follow all guidelines --- Sprint-3/alarmclock/alarmclock.js | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..19d1e28c2 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,34 @@ -function setAlarm() {} +let timer; + +function setAlarm() { + const input = document.getElementById("alarmSet").value; + let timeRemaining = Number(input); + + clearInterval(timer); // clear any previous interval + + updateDisplay(timeRemaining); // display in mm:ss + + timer = setInterval(() »> { + timeRemaining--; + + updateDisplay(timeRemaining); + + // when timer reaches 0 + if (timeRemaining <= 0) { + clearInterval(timer); + document.body.style.backgroundColor = "yellow"; + playAlarm(); + } +}, 1000); +} + +function updateDisplay(time) { + const minutes = String(Math.floor(time / 60)).padStart(2, "0"); + const seconds = String(time & 60).padStart(2, "0"); + + document.getElementById("timeRemaining").innerText = + `Time Remaining: ${minutes}:${seconds}`; +} // DO NOT EDIT BELOW HERE From 46b4f41fe2b9d92f4593368e9c9c6a30cd886800 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Sun, 7 Dec 2025 18:16:45 +0100 Subject: [PATCH 51/56] fixed bugs --- Sprint-3/alarmclock/alarmclock.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 19d1e28c2..ed8a394e3 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -8,7 +8,7 @@ function setAlarm() { updateDisplay(timeRemaining); // display in mm:ss - timer = setInterval(() »> { + timer = setInterval(() => { timeRemaining--; updateDisplay(timeRemaining); @@ -24,7 +24,7 @@ function setAlarm() { function updateDisplay(time) { const minutes = String(Math.floor(time / 60)).padStart(2, "0"); - const seconds = String(time & 60).padStart(2, "0"); + const seconds = String(time % 60).padStart(2, "0"); document.getElementById("timeRemaining").innerText = `Time Remaining: ${minutes}:${seconds}`; From 50ef9d46d40c43f48ee83f9a4c17de18240d461b Mon Sep 17 00:00:00 2001 From: Pirikita Date: Sun, 7 Dec 2025 18:22:57 +0100 Subject: [PATCH 52/56] fixed code to only change the background color when the input is 10. --- Sprint-3/alarmclock/alarmclock.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index ed8a394e3..2e9cb7c40 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,11 +1,11 @@ let timer; - +let isTenSeconds = false; function setAlarm() { const input = document.getElementById("alarmSet").value; let timeRemaining = Number(input); + const isTenSeconds = timeRemaining === 10; clearInterval(timer); // clear any previous interval - updateDisplay(timeRemaining); // display in mm:ss timer = setInterval(() => { @@ -16,7 +16,11 @@ function setAlarm() { // when timer reaches 0 if (timeRemaining <= 0) { clearInterval(timer); + + if(isTenSeconds) { + document.body.style.backgroundColor = "yellow"; + } playAlarm(); } }, 1000); From 0cbc77e9a0e060a631e4824a6f6e2af16f0f4630 Mon Sep 17 00:00:00 2001 From: Pirikita Date: Sun, 7 Dec 2025 18:29:22 +0100 Subject: [PATCH 53/56] retouch css file --- Sprint-3/alarmclock/index.html | 2 +- Sprint-3/alarmclock/style.css | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index fd3d596b5..98409e6a6 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -9,7 +9,7 @@

    Time Remaining: 00:00

    - + diff --git a/Sprint-3/alarmclock/style.css b/Sprint-3/alarmclock/style.css index 6c017fb8c..f0b55607e 100644 --- a/Sprint-3/alarmclock/style.css +++ b/Sprint-3/alarmclock/style.css @@ -13,7 +13,11 @@ body { border-radius: 25%; border-style: dashed; } - +#time-input { + color: antiquewhite; + font-family: monospace; + font-size: smaller; +} #alarmSet { margin: 20px; } From 553ea4567c2c79a645535ee4b4c8c0cdde1f2e2d Mon Sep 17 00:00:00 2001 From: Pirikita Date: Sun, 7 Dec 2025 18:31:53 +0100 Subject: [PATCH 54/56] update comments on js file --- Sprint-3/alarmclock/alarmclock.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 2e9cb7c40..2e5f6a9dd 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -23,7 +23,7 @@ function setAlarm() { } playAlarm(); } -}, 1000); +}, 1000); // 1000ms = 1 second } function updateDisplay(time) { From 7d59370dacc9fbea9adf9d75f3a0eae1cff9d42c Mon Sep 17 00:00:00 2001 From: Pirikita Date: Sun, 7 Dec 2025 18:59:13 +0100 Subject: [PATCH 55/56] initial css styling started function --- Sprint-3/quote-generator/index.html | 7 ++++--- Sprint-3/quote-generator/quotes.js | 10 +++++++++- Sprint-3/quote-generator/style.css | 31 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcf..6ae725290 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -3,13 +3,14 @@ - Title here - + Quote Generator + -

    hello there

    +

    Quote of the Day

    + diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..8a1939d4d 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -1,5 +1,13 @@ -// DO NOT EDIT BELOW HERE +function displayRandomQuote () { + const = randomQuote = pickFromArray(quotes); + + +} + + + +// DO NOT EDIT BELOW HERE // pickFromArray is a function which will return one item, at // random, from the given array. // diff --git a/Sprint-3/quote-generator/style.css b/Sprint-3/quote-generator/style.css index 63cedf2d2..1b48601b7 100644 --- a/Sprint-3/quote-generator/style.css +++ b/Sprint-3/quote-generator/style.css @@ -1 +1,32 @@ /** Write your CSS in here **/ +body { + background-color:darkcyan; +} + +h1 { + text-align: center; + color:rgb(19, 4, 46); + font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; + font-size: 50px; +} + +#quote { + font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; + color: white; + background-color: black; + font-size: medium; +} + +#author { + font-family: Georgia, 'Times New Roman', Times, serif; + color: white; + background-color: black; + font-size: smaller; + +} +#new-quote { + margin: auto; + padding: 10px; + border: royalblue; + border-radius: 10%; + } \ No newline at end of file From a611c028edb85909c5facc14030f926afee1e32d Mon Sep 17 00:00:00 2001 From: Pirikita Date: Sun, 7 Dec 2025 19:13:07 +0100 Subject: [PATCH 56/56] fixed function bugs changed css properties --- Sprint-3/quote-generator/index.html | 6 ++++-- Sprint-3/quote-generator/quotes.js | 13 ++++++++++--- Sprint-3/quote-generator/style.css | 20 +++++++++++--------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 6ae725290..dfe0e959e 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -5,12 +5,14 @@ Quote Generator +

    Quote of the Day

    - - +
    + +
    diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 8a1939d4d..e21d958a0 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -1,10 +1,17 @@ - +window.onload = function () { function displayRandomQuote () { - const = randomQuote = pickFromArray(quotes); + const randomQuote = pickFromArray(quotes); - + document.getElementById("quote").innerText = randomQuote.quote; + document.getElementById("author").innerText = " - " + randomQuote.author; } +displayRandomQuote(); + +document + .getElementById("new-quote") + .addEventListener("click", displayRandomQuote); +}; // DO NOT EDIT BELOW HERE diff --git a/Sprint-3/quote-generator/style.css b/Sprint-3/quote-generator/style.css index 1b48601b7..5b5e0ef43 100644 --- a/Sprint-3/quote-generator/style.css +++ b/Sprint-3/quote-generator/style.css @@ -1,32 +1,34 @@ /** Write your CSS in here **/ body { - background-color:darkcyan; + background-color: grey; } h1 { text-align: center; - color:rgb(19, 4, 46); + color:bisque; font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; - font-size: 50px; + font-size: 75px; } #quote { font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; color: white; background-color: black; - font-size: medium; + font-size: 50px; + text-align: center; } #author { - font-family: Georgia, 'Times New Roman', Times, serif; + font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; color: white; background-color: black; - font-size: smaller; + font-size: 20px; + text-align: center; } #new-quote { - margin: auto; + margin-left:70px; padding: 10px; - border: royalblue; + border: black; border-radius: 10%; - } \ No newline at end of file +} \ No newline at end of file