From 7a32b228aa69900c13723c47a70d6a40cb31f6ba Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Mon, 13 Apr 2026 01:56:55 +0100 Subject: [PATCH 01/12] Doing the first part if the sprint 2 --- Sprint-2/debug/address.js | 4 ++-- Sprint-2/debug/author.js | 2 +- Sprint-2/debug/recipe.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 940a6af83..3bcdc4ed5 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -5,11 +5,11 @@ // Fix anything that isn't working const address = { - houseNumber: 42, + houseNumber: "42", street: "Imaginary Road", city: "Manchester", country: "England", postcode: "XYZ 123", }; -console.log(`My house number is ${address[0]}`); +console.log(`My house number is ${address["houseNumber"]}`); diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 8c2125977..f335982e4 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -11,6 +11,6 @@ const author = { alive: true, }; -for (const value of author) { +for (const value in author) { console.log(value); } diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cd..d0b246f22 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -12,4 +12,4 @@ const recipe = { console.log(`${recipe.title} serves ${recipe.serves} ingredients: -${recipe}`); +${recipe.ingredients}`); From 25def281bfc8fafd6f8f1027e688042bdc7dce1e Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Thu, 16 Apr 2026 00:35:54 +0100 Subject: [PATCH 02/12] Making basic change and writing test --- Sprint-2/implement/contains.js | 10 +++++++++- Sprint-2/implement/contains.test.js | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a..2b01e60ae 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,11 @@ -function contains() {} +function contains(object, key) { + for (const item in object){ + if(item === key){ + return true; + }else { + return false; + } +} +} module.exports = contains; diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 326bdb1f2..b68f64901 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -16,11 +16,16 @@ 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("should return true if the input object contain the key value", () => { + let normalObject = {a:1,b:2,c:3,d:4}; + expect(contains(normalObject,"a")).toBe(true); + expect(contains(normalObject,"f")).toBe(false); +}); // Given an empty object // When passed to contains // Then it should return false -test.todo("contains on empty object returns false"); +test("contains on empty object returns false"); // Given an object with properties // When passed to contains with an existing property name From 2ff2c05f1443cee567d2087373d244c6dafb561c Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Thu, 16 Apr 2026 01:27:07 +0100 Subject: [PATCH 03/12] finish the first part of implement --- Sprint-2/implement/contains.js | 19 ++++++++++++++----- Sprint-2/implement/contains.test.js | 27 ++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 2b01e60ae..fdd6f892e 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,11 +1,20 @@ function contains(object, key) { - for (const item in object){ - if(item === key){ - return true; - }else { + if (Object.keys(object).length === 0) { return false; } -} + + for (const checkItem in object){ + let validation = object[checkItem] + if(Array.isArray(validation)){ + return false; + } + } + for (const item in object) { + if (item === key) { + return true; + } + } + return false; } module.exports = contains; diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index b68f64901..aa4b78641 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -17,24 +17,41 @@ as the object doesn't contains a key of 'c' // When passed an object and a property name // Then it should return true if the object contains the property, false otherwise test("should return true if the input object contain the key value", () => { - let normalObject = {a:1,b:2,c:3,d:4}; - expect(contains(normalObject,"a")).toBe(true); - expect(contains(normalObject,"f")).toBe(false); + expect(contains({a:1,b:2,c:3,d:4},"a")).toBe(true); + expect(contains({a:1,b:2,c:3,d:4},"f")).toBe(false); }); // Given an empty object // When passed to contains // Then it should return false -test("contains on empty object returns false"); +test("should return false if the object is empty", () => { + let emptyObject = {}; + expect(contains(emptyObject,"a")).toBe(false); +}); // Given an object with properties // When passed to contains with an existing property name // Then it should return true +test("should return true if the input object contain existing key value", () => { + let infoObject = {name:"John",age:"24",city:"Glasgow"}; + expect(contains(infoObject,"name")).toBe(true); + expect(contains(infoObject,"age")).toBe(true); + expect(contains(infoObject,"city")).toBe(true); +}); // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false - +test("should return false if the input object do not have non existing key value", () => { + let goodsObject = {fruit:"Apple",amount:"50",origin:"Glasgow"}; + expect(contains(goodsObject,"tree")).toBe(false); + expect(contains(goodsObject,"color")).toBe(false); + expect(contains(goodsObject,"country")).toBe(false); +}); // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error +test("should return false if the input object do not have non existing key value", () => { + let mixObject = {a:2,b:"hello",c:[]}; + expect(contains(mixObject,"c")).toBe(false); +}); \ No newline at end of file From eaffafc9720c97ae36dfd61d624d46adfaae1268 Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Sat, 18 Apr 2026 00:14:50 +0100 Subject: [PATCH 04/12] Commit for loop up --- Sprint-2/implement/lookup.js | 9 ++++++++- Sprint-2/implement/lookup.test.js | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index a6746e07f..1e0b6b51d 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,5 +1,12 @@ -function createLookup() { +function createLookup(pairs) { // implementation here + let countryPair = {}; + for (const [country, currency] of pairs) { + countryPair[country] = currency; + } + + return countryPair; } module.exports = createLookup; + diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 547e06c5a..19ea8327c 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -1,6 +1,23 @@ const createLookup = require("./lookup.js"); -test.todo("creates a country currency code lookup for multiple codes"); +test("creates a country currency code in an lookup array for multiple codes, and return in object form", () => { + let worldCurrency = [ + ["US","USD"], + ["GB","POUND"], + ["FRC","EURO"], + ["JP","YEN"], + ["KR","WON"], + ["MX","PESO"], + ]; + expect(createLookup(worldCurrency)).toEqual({ + US: "USD", + GB: "POUND", + FRC: "EURO", + JP: "YEN", + KR: "WON", + MX: "PESO", + }); +}); /* From 4d7b72ce4baea1cf13048e8be2ed86e4f7d7cb82 Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Sat, 18 Apr 2026 02:18:37 +0100 Subject: [PATCH 05/12] finish the tally course work --- Sprint-2/implement/tally.js | 16 +++++++++++++++- Sprint-2/implement/tally.test.js | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index f47321812..19de78489 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,3 +1,17 @@ -function tally() {} +function tally(sumArray) { + if (sumArray.length === 0) return {} ; + if (!Array.isArray(sumArray)){ + throw new Error("Input musk be an array") + } + let totalSum = {}; + for (const item of sumArray) { + if (totalSum[item] === undefined) { + totalSum[item] = 1; + } else { + totalSum[item] += 1; + } + } + return totalSum; +} module.exports = tally; diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 2ceffa8dd..3c61a1fdc 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -23,12 +23,22 @@ const tally = require("./tally.js"); // 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("tally on an empty array returns an empty object",() =>{ +let emptyObject =[]; +expect(tally(emptyObject)).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 returns with correct amount object",() =>{ +let firstObject =["a","a","c","b","c","b","a","c",]; +expect(tally(firstObject)).toEqual({a:3,b:2,c:3}); +}); // Given an invalid input like a string // When passed to tally // Then it should throw an error +test("tally on a string should throw invalid input",() =>{ +let stringInput = "input"; +expect(() => tally(stringInput)).toThrow("Input musk be an array"); +}); \ No newline at end of file From 9251977d6f0ff1a36072c669295eebb8b12bda07 Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Sat, 18 Apr 2026 12:37:59 +0100 Subject: [PATCH 06/12] For the final section for PR submission --- Sprint-2/implement/querystring.js | 16 ++++++++++++---- Sprint-2/interpret/invert.js | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 45ec4e5f3..5ccd31d75 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -1,12 +1,20 @@ function parseQueryString(queryString) { const queryParams = {}; - if (queryString.length === 0) { + + if (!queryString || queryString.length === 0) { return queryParams; } - const keyValuePairs = queryString.split("&"); - for (const pair of keyValuePairs) { - const [key, value] = pair.split("="); + const pairs = queryString.split("&"); + + for (const pair of pairs) { + if (!pair) continue; + + const [key, ...rest] = pair.split("="); + const value = rest.join("="); + + if (!key) continue; + queryParams[key] = value; } diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index bb353fb1f..c89a3aee5 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -10,20 +10,33 @@ function invert(obj) { const invertedObj = {}; for (const [key, value] of Object.entries(obj)) { - invertedObj.key = value; + invertedObj[value] = key; } return invertedObj; } +console.log(invert({ a: 1 })); +console.log(invert({ a: 1, b: 2 })); +console.log(invert({ a: 1, b: 2 })); // a) What is the current return value when invert is called with { a : 1 } +// the current output value of this invert is {key:1}. // b) What is the current return value when invert is called with { a: 1, b: 2 } +/* the current output value of this invert is {key:2} because +instead of accessing the [key] variable inside the condition parameter for store key for each loop, the code in line 13 instead adding .key behind and the system +interpret as string literal so each loop is overwrite the previous key value. +.*/ // c) What is the target return value when invert is called with {a : 1, b: 2} +// is also the same with { a: 1, b: 2 } because is overwrite the previous key each loop. // c) What does Object.entries return? Why is it needed in this program? +/* Object.entries return deconstruct object key and value pair into individual item in an array. +This is very important because since object is are not iterable, this help by deconstructing object into array when we try to loop each key and value pair*/ // d) Explain why the current return value is different from the target output - +/* +Because inside the for of loop, the invertedObj output assign they keys first instead of value for each loop. +*/ // e) Fix the implementation of invert (and write tests to prove it's fixed!) From 33d17a2bd40656466ff86e200c2779bffd4b1bc0 Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Sun, 19 Apr 2026 00:30:55 +0100 Subject: [PATCH 07/12] Formatting all the file in sprint 2 --- Sprint-2/implement/contains.js | 10 ++++----- Sprint-2/implement/contains.test.js | 28 +++++++++++++------------- Sprint-2/implement/lookup.js | 9 ++++----- Sprint-2/implement/lookup.test.js | 12 +++++------ Sprint-2/implement/querystring.test.js | 4 ++-- Sprint-2/implement/tally.js | 6 +++--- Sprint-2/implement/tally.test.js | 20 +++++++++--------- Sprint-3/alarmclock/index.html | 2 +- 8 files changed, 45 insertions(+), 46 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index fdd6f892e..6e2f5136c 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -3,18 +3,18 @@ function contains(object, key) { return false; } - for (const checkItem in object){ - let validation = object[checkItem] - if(Array.isArray(validation)){ + for (const checkItem in object) { + let validation = object[checkItem]; + if (Array.isArray(validation)) { return false; - } + } } for (const item in object) { if (item === key) { return true; } } - return false; + return false; } module.exports = contains; diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index aa4b78641..31d6fd3ae 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -17,8 +17,8 @@ as the object doesn't contains a key of 'c' // When passed an object and a property name // Then it should return true if the object contains the property, false otherwise test("should return true if the input object contain the key value", () => { - expect(contains({a:1,b:2,c:3,d:4},"a")).toBe(true); - expect(contains({a:1,b:2,c:3,d:4},"f")).toBe(false); + expect(contains({ a: 1, b: 2, c: 3, d: 4 }, "a")).toBe(true); + expect(contains({ a: 1, b: 2, c: 3, d: 4 }, "f")).toBe(false); }); // Given an empty object @@ -26,32 +26,32 @@ test("should return true if the input object contain the key value", () => { // Then it should return false test("should return false if the object is empty", () => { let emptyObject = {}; - expect(contains(emptyObject,"a")).toBe(false); + expect(contains(emptyObject, "a")).toBe(false); }); // Given an object with properties // When passed to contains with an existing property name // Then it should return true test("should return true if the input object contain existing key value", () => { - let infoObject = {name:"John",age:"24",city:"Glasgow"}; - expect(contains(infoObject,"name")).toBe(true); - expect(contains(infoObject,"age")).toBe(true); - expect(contains(infoObject,"city")).toBe(true); + let infoObject = { name: "John", age: "24", city: "Glasgow" }; + expect(contains(infoObject, "name")).toBe(true); + expect(contains(infoObject, "age")).toBe(true); + expect(contains(infoObject, "city")).toBe(true); }); // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false test("should return false if the input object do not have non existing key value", () => { - let goodsObject = {fruit:"Apple",amount:"50",origin:"Glasgow"}; - expect(contains(goodsObject,"tree")).toBe(false); - expect(contains(goodsObject,"color")).toBe(false); - expect(contains(goodsObject,"country")).toBe(false); + let goodsObject = { fruit: "Apple", amount: "50", origin: "Glasgow" }; + expect(contains(goodsObject, "tree")).toBe(false); + expect(contains(goodsObject, "color")).toBe(false); + expect(contains(goodsObject, "country")).toBe(false); }); // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error test("should return false if the input object do not have non existing key value", () => { - let mixObject = {a:2,b:"hello",c:[]}; - expect(contains(mixObject,"c")).toBe(false); -}); \ No newline at end of file + let mixObject = { a: 2, b: "hello", c: [] }; + expect(contains(mixObject, "c")).toBe(false); +}); diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index 1e0b6b51d..39330cd17 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,12 +1,11 @@ function createLookup(pairs) { // implementation here let countryPair = {}; - for (const [country, currency] of pairs) { - countryPair[country] = currency; - } + for (const [country, currency] of pairs) { + countryPair[country] = currency; + } - return countryPair; + return countryPair; } module.exports = createLookup; - diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 19ea8327c..d77330cc2 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -2,12 +2,12 @@ const createLookup = require("./lookup.js"); test("creates a country currency code in an lookup array for multiple codes, and return in object form", () => { let worldCurrency = [ - ["US","USD"], - ["GB","POUND"], - ["FRC","EURO"], - ["JP","YEN"], - ["KR","WON"], - ["MX","PESO"], + ["US", "USD"], + ["GB", "POUND"], + ["FRC", "EURO"], + ["JP", "YEN"], + ["KR", "WON"], + ["MX", "PESO"], ]; expect(createLookup(worldCurrency)).toEqual({ US: "USD", diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 3e218b789..717ee6901 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -3,10 +3,10 @@ // Below is one test case for an edge case the implementation doesn't handle well. // Fix the implementation for this test, and try to think of as many other edge cases as possible - write tests and fix those too. -const parseQueryString = require("./querystring.js") +const parseQueryString = require("./querystring.js"); test("parses querystring values containing =", () => { expect(parseQueryString("equation=x=y+1")).toEqual({ - "equation": "x=y+1", + equation: "x=y+1", }); }); diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 19de78489..94fe9bf07 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,7 +1,7 @@ function tally(sumArray) { - if (sumArray.length === 0) return {} ; - if (!Array.isArray(sumArray)){ - throw new Error("Input musk be an array") + if (sumArray.length === 0) return {}; + if (!Array.isArray(sumArray)) { + throw new Error("Input musk be an array"); } let totalSum = {}; for (const item of sumArray) { diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 3c61a1fdc..a1f891333 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -23,22 +23,22 @@ const tally = require("./tally.js"); // Given an empty array // When passed to tally // Then it should return an empty object -test("tally on an empty array returns an empty object",() =>{ -let emptyObject =[]; -expect(tally(emptyObject)).toEqual({}); +test("tally on an empty array returns an empty object", () => { + let emptyObject = []; + expect(tally(emptyObject)).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 returns with correct amount object",() =>{ -let firstObject =["a","a","c","b","c","b","a","c",]; -expect(tally(firstObject)).toEqual({a:3,b:2,c:3}); +test("tally on an array with duplicate returns with correct amount object", () => { + let firstObject = ["a", "a", "c", "b", "c", "b", "a", "c"]; + expect(tally(firstObject)).toEqual({ a: 3, b: 2, c: 3 }); }); // Given an invalid input like a string // When passed to tally // Then it should throw an error -test("tally on a string should throw invalid input",() =>{ -let stringInput = "input"; -expect(() => tally(stringInput)).toThrow("Input musk be an array"); -}); \ No newline at end of file +test("tally on a string should throw invalid input", () => { + let stringInput = "input"; + expect(() => tally(stringInput)).toThrow("Input musk be an array"); +}); diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..ff2d3b453 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock app
From db07953ba0ff4f31533a61020ede73dad68c37fa Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Sun, 19 Apr 2026 00:52:23 +0100 Subject: [PATCH 08/12] Making change in the debug section --- Sprint-2/debug/author.js | 4 ++-- Sprint-2/debug/recipe.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index f335982e4..2ead84603 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -2,7 +2,7 @@ // 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 - +// this function have 2 bugs, one is that the since object is not iterable so by using for of loop is will not work. The second is that is only print out property name not property value const author = { firstName: "Zadie", lastName: "Smith", @@ -12,5 +12,5 @@ const author = { }; for (const value in author) { - console.log(value); + console.log(author[value]); } diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index d0b246f22..a413b3332 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -12,4 +12,4 @@ const recipe = { console.log(`${recipe.title} serves ${recipe.serves} ingredients: -${recipe.ingredients}`); +${recipe.ingredients.join("\n")}`); From 2a3243b77ee07ca31d2b128971243536d34fbecc Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Sun, 19 Apr 2026 01:21:02 +0100 Subject: [PATCH 09/12] fixing the validation when array as a property value --- Sprint-2/implement/contains.js | 16 +++++++++++++--- Sprint-2/implement/contains.test.js | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 6e2f5136c..5ed4b9840 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,19 +1,29 @@ function contains(object, key) { + if ( + object === null || + object === undefined || + typeof object !== "object" || + Array.isArray(object) + ) { + return false; + } + if (Object.keys(object).length === 0) { return false; } - for (const checkItem in object) { - let validation = object[checkItem]; - if (Array.isArray(validation)) { + for (const item in object) { + if (Array.isArray(object[item])) { return false; } } + for (const item in object) { if (item === key) { return true; } } + return false; } diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 31d6fd3ae..114febaac 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -54,4 +54,10 @@ test("should return false if the input object do not have non existing key value test("should return false if the input object do not have non existing key value", () => { let mixObject = { a: 2, b: "hello", c: [] }; expect(contains(mixObject, "c")).toBe(false); + + +expect(contains(["A", "B"], "1" )).toBe(false); +expect(contains(null, "1" )).toBe(false); +expect(contains(undefined, "1" )).toBe(false); +expect(contains("ABC", "1" )).toBe(false); }); From ccce68852cf97b735d8b02d6fdb8aee36f120a57 Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Sun, 19 Apr 2026 01:30:16 +0100 Subject: [PATCH 10/12] Final change before re submit --- Sprint-2/implement/tally.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 94fe9bf07..954204cd2 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -5,7 +5,7 @@ function tally(sumArray) { } let totalSum = {}; for (const item of sumArray) { - if (totalSum[item] === undefined) { + if (!Object.hasOwn(totalSum, item)) { totalSum[item] = 1; } else { totalSum[item] += 1; @@ -13,5 +13,4 @@ function tally(sumArray) { } return totalSum; } - module.exports = tally; From 5cf45929373a26c65b5677bf761b521ee4ed4153 Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Sun, 19 Apr 2026 01:33:34 +0100 Subject: [PATCH 11/12] format the new test given by review for future study --- Sprint-2/implement/contains.test.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 114febaac..cd82b0fb4 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -54,10 +54,8 @@ test("should return false if the input object do not have non existing key value test("should return false if the input object do not have non existing key value", () => { let mixObject = { a: 2, b: "hello", c: [] }; expect(contains(mixObject, "c")).toBe(false); - - -expect(contains(["A", "B"], "1" )).toBe(false); -expect(contains(null, "1" )).toBe(false); -expect(contains(undefined, "1" )).toBe(false); -expect(contains("ABC", "1" )).toBe(false); + expect(contains(["A", "B"], "1")).toBe(false); + expect(contains(null, "1")).toBe(false); + expect(contains(undefined, "1")).toBe(false); + expect(contains("ABC", "1")).toBe(false); }); From fcfb3ef788561eb707fd5d7e48d36f19184c7544 Mon Sep 17 00:00:00 2001 From: Jacknguyen4438 Date: Sun, 19 Apr 2026 17:39:13 +0100 Subject: [PATCH 12/12] Making change for resubmit for PR --- Sprint-2/implement/contains.js | 14 +------------- Sprint-2/implement/contains.test.js | 4 ++-- Sprint-2/implement/tally.js | 4 +++- Sprint-3/alarmclock/index.html | 2 +- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 5ed4b9840..850d98933 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,10 +1,5 @@ function contains(object, key) { - if ( - object === null || - object === undefined || - typeof object !== "object" || - Array.isArray(object) - ) { + if (object === null || typeof object !== "object" || Array.isArray(object)) { return false; } @@ -12,18 +7,11 @@ function contains(object, key) { return false; } - for (const item in object) { - if (Array.isArray(object[item])) { - return false; - } - } - for (const item in object) { if (item === key) { return true; } } - return false; } diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index cd82b0fb4..6b0573531 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -51,9 +51,9 @@ test("should return false if the input object do not have non existing key value // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error -test("should return false if the input object do not have non existing key value", () => { +test("should return false if the input parameters is an array or not an object", () => { let mixObject = { a: 2, b: "hello", c: [] }; - expect(contains(mixObject, "c")).toBe(false); + expect(contains(mixObject, "c")).toBe(true); expect(contains(["A", "B"], "1")).toBe(false); expect(contains(null, "1")).toBe(false); expect(contains(undefined, "1")).toBe(false); diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 954204cd2..1cff3b5c2 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,8 +1,10 @@ function tally(sumArray) { - if (sumArray.length === 0) return {}; if (!Array.isArray(sumArray)) { throw new Error("Input musk be an array"); } + + if (sumArray.length === 0) return {}; + let totalSum = {}; for (const item of sumArray) { if (!Object.hasOwn(totalSum, item)) { diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index ff2d3b453..48e2e80d9 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Alarm clock app + Title here