From 9b10ba6d1591d8561e582954fbac31fb8dd12544 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Fri, 6 Nov 2026 14:42:31 +0000 Subject: [PATCH 01/53] made a prediction about the error in the file address.js --- 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 940a6af832..8fce56a5e8 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,5 +1,7 @@ // Predict and explain first... +// my prediction is that this is not indexed array. it is an array that uses key. + // This code should log out the houseNumber from the address object // but it isn't working... // Fix anything that isn't working From 586987d6593ec2dd9071293f03556d4a0192382d Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Fri, 6 Nov 2026 14:50:11 +0000 Subject: [PATCH 02/53] made the necessary change to fix the error --- 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 8fce56a5e8..61e747b5dc 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -14,4 +14,4 @@ const address = { postcode: "XYZ 123", }; -console.log(`My house number is ${address[0]}`); +console.log(`My house number is ${address.houseNumber}`); From 9dbc72a3bc929eb4c8cb4da6cd263dac3961edd4 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Fri, 6 Nov 2026 15:33:07 +0000 Subject: [PATCH 03/53] gave my prediction and explained about the bug --- Sprint-2/debug/author.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 8c2125977d..a56ec699c0 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,5 +1,8 @@ // Predict and explain first... +// my prediction here is that we can not use for..of loop because author is not iterable. +// The reason is, it doesnt use indices it uses keys.instead we will use for..in loop. + // 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 59f4ca7edaafbb00a2610aa6b64898d2efabbe38 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Fri, 6 Nov 2026 15:37:28 +0000 Subject: [PATCH 04/53] made further explanation for the error --- Sprint-2/debug/author.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index a56ec699c0..b15b878953 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -6,6 +6,9 @@ // 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 +// As I said earlier it is not using index, we can not iterate it with +// for ..of loop. The output also gonna be the key so we have to change that as well. + const author = { firstName: "Zadie", lastName: "Smith", @@ -14,6 +17,6 @@ const author = { alive: true, }; -for (const value of author) { +for (const value in author) { console.log(value); } From 759cd2f8b078f9400e61c8573a98ccf0f6a75364 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Fri, 6 Nov 2026 15:39:16 +0000 Subject: [PATCH 05/53] edited the code to make the code bug free. works well now --- Sprint-2/debug/author.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index b15b878953..0f30db890b 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -17,6 +17,6 @@ const author = { alive: true, }; -for (const value in author) { - console.log(value); +for (const key in author) { + console.log(author[key]); } From 5a26afc4ac937def1aef0cd0bd33e5a0f21d9256 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Fri, 6 Nov 2026 16:12:15 +0000 Subject: [PATCH 06/53] gave my prediction,explanation and edited the code to get the desired output --- Sprint-2/debug/recipe.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cdc..2f04d07036 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,15 +1,21 @@ // Predict and explain first... +// My prediction is that ingredients are not gonna be printed out. because the object +// is not attached to the key in the console.log. // 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? +// We can fix it by using for..of loop for the array . + const recipe = { title: "bruschetta", serves: 2, ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title} serves ${recipe.serves} - ingredients: -${recipe}`); +console.log(`${recipe.title} serves ${recipe.serves}`); + +for (const item of recipe.ingredients) { + console.log(item); +} From fc407f24c0ae9573445c9ac4762d5d13d6ce3b38 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 8 Nov 2026 16:49:52 +0000 Subject: [PATCH 07/53] added test tha t should return true when it contains the proerty. test failed --- Sprint-2/implement/contains.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 719272787d..37aefeeb19 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -19,6 +19,12 @@ as an array isn't an object // 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 when an object contains the property", () => { + const object1 = { a: 1, b: 2, c: 3 }; + const property = "a"; + const result = contains(object1, property); + expect(result).toEqual(true); +}); // Given an empty object // When passed to contains From ec28696a6817f6e403f8cc35076848a8d5620415 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 8 Nov 2026 16:50:46 +0000 Subject: [PATCH 08/53] added a test just to pass the test. test passed --- Sprint-2/implement/contains.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a0..c17e033a0d 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,5 @@ -function contains() {} +function contains() { + return true; +} module.exports = contains; From b1637b2bd25d353dad327326199c4c268eadf5a7 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 8 Nov 2026 18:53:51 +0000 Subject: [PATCH 09/53] added a test for empty object test failed --- Sprint-2/implement/contains.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 37aefeeb19..4274679958 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -30,6 +30,12 @@ test("should return true when an object contains the property", () => { // When passed to contains // Then it should return false test.todo("contains on empty object returns false"); +test("should return false when empty object is passed", () => { + const object1 = {}; + const property = "a"; + const result = contains(object1, property); + expect(result).toEqual(false); +}); // Given an object with properties // When passed to contains with an existing property name From d14c2b12894192a36a030384182910ed1ae2ced7 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 8 Nov 2026 19:10:05 +0000 Subject: [PATCH 10/53] added a code to make the test pass and.tess passed --- Sprint-2/implement/contains.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index c17e033a0d..8bea3af41c 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,4 +1,7 @@ -function contains() { +function contains(objIn, property) { + if (Object.keys(objIn).length === 0) { + return false; + } return true; } From f48a0d2c64699834415754fa7f825bc421424419 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 8 Nov 2026 19:23:20 +0000 Subject: [PATCH 11/53] 1 test failed that should return false when a proprety name doesn't much --- Sprint-2/implement/contains.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 4274679958..40ab087177 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -40,11 +40,23 @@ test("should return false when empty object is passed", () => { // Given an object with properties // When passed to contains with an existing property name // Then it should return true +test("should return true when object is passed and property name matches the", () => { + const object1 = { a: 1, b: 2, c: 3, d: 4 }; + const property = "b"; + const result = contains(object1, property); + expect(result).toEqual(true); +}); // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false +test("should return true when object is passed and property name matches the", () => { + const object1 = { a: 1, b: 2, c: 3, d: 4 }; + const property = "e"; + const result = contains(object1, property); + expect(result).toEqual(false); +}); // Given a value that isn't an object - an array, a string, a number, // null, or no argument at all // When passed to contains From 0fd541f330640cc8ac1806d2d0c958be51761271 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 8 Nov 2026 20:13:20 +0000 Subject: [PATCH 12/53] added a test that throws an error if value is not object. test failed --- Sprint-2/implement/contains.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 40ab087177..b86b986026 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -40,7 +40,7 @@ test("should return false when empty object is passed", () => { // Given an object with properties // When passed to contains with an existing property name // Then it should return true -test("should return true when object is passed and property name matches the", () => { +test("should return true when object is passed and property name matches", () => { const object1 = { a: 1, b: 2, c: 3, d: 4 }; const property = "b"; const result = contains(object1, property); @@ -51,7 +51,7 @@ test("should return true when object is passed and property name matches the", ( // When passed to contains with a non-existent property name // Then it should return false -test("should return true when object is passed and property name matches the", () => { +test("should return false when object is passed and property name doesnt matches ", () => { const object1 = { a: 1, b: 2, c: 3, d: 4 }; const property = "e"; const result = contains(object1, property); @@ -62,3 +62,6 @@ test("should return true when object is passed and property name matches the", ( // When passed to contains // Then it should throw Error("contains requires an object") // (careful: typeof [] and typeof null are both "object") +test("should throw an error when the valu passed isn't an object", () => { + expect(() => contains([])).toThrow("contains requires an object"); +}); From 5d3bf95de3013553f6a525ff696cbbdecb37a8ed Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 8 Nov 2026 20:14:12 +0000 Subject: [PATCH 13/53] edited the code and tests passed except for throwing an error --- Sprint-2/implement/contains.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 8bea3af41c..a140c3a430 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,8 +1,14 @@ function contains(objIn, property) { - if (Object.keys(objIn).length === 0) { - return false; + for (const key in objIn) { + if (key === property) { + return true; + } } - return true; + return false; } +// if (Object.keys(objIn).length === 0 && property !== "") { +// return false; +// } +// return true; module.exports = contains; From 6ac330d504802ba741ba454671e578f7a44d241a Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 8 Nov 2026 20:37:20 +0000 Subject: [PATCH 14/53] added to make a test pass to throw an error and it did --- Sprint-2/implement/contains.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index a140c3a430..aa8ea758af 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,4 +1,8 @@ function contains(objIn, property) { + if (Array.isArray(objIn)) { + throw new Error("contains requires an object"); + } + for (const key in objIn) { if (key === property) { return true; From 10992d0b9d6cc3f118575dea6cec217656db44b8 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 8 Nov 2026 21:34:20 +0000 Subject: [PATCH 15/53] added some code for throwing error properly, it worked and test passed --- Sprint-2/implement/contains.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index aa8ea758af..3a24f3903c 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,5 +1,5 @@ function contains(objIn, property) { - if (Array.isArray(objIn)) { + if (Array.isArray(objIn) || objIn === null || typeof objIn !== "object") { throw new Error("contains requires an object"); } @@ -10,9 +10,5 @@ function contains(objIn, property) { } return false; } -// if (Object.keys(objIn).length === 0 && property !== "") { -// return false; -// } -// return true; module.exports = contains; From 9e03adc90a6e1bb8e2bfbe1f8537e6cb4b339145 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 8 Nov 2026 21:36:06 +0000 Subject: [PATCH 16/53] added some more tests on giving null ,numbers and no agrument .test passed --- Sprint-2/implement/contains.test.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index b86b986026..46b0da97ac 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -29,7 +29,6 @@ test("should return true when an object contains the property", () => { // Given an empty object // When passed to contains // Then it should return false -test.todo("contains on empty object returns false"); test("should return false when empty object is passed", () => { const object1 = {}; const property = "a"; @@ -46,6 +45,12 @@ test("should return true when object is passed and property name matches", () => const result = contains(object1, property); expect(result).toEqual(true); }); +test("should return true when object is passed and property name matches", () => { + const object1 = { name: "sharon", age: 30, hobby: "photography" }; + const property = "hobby"; + const result = contains(object1, property); + expect(result).toEqual(true); +}); // Given an object with properties // When passed to contains with a non-existent property name @@ -62,6 +67,18 @@ test("should return false when object is passed and property name doesnt matches // When passed to contains // Then it should throw Error("contains requires an object") // (careful: typeof [] and typeof null are both "object") -test("should throw an error when the valu passed isn't an object", () => { - expect(() => contains([])).toThrow("contains requires an object"); +test("should throw an error when the value passed is Array", () => { + expect(() => contains([1, 2, 3])).toThrow("contains requires an object"); +}); +test("should throw an error when the value passed is null", () => { + expect(() => contains(null)).toThrow("contains requires an object"); +}); +test("should throw an error when the valu passed is a string", () => { + expect(() => contains("null")).toThrow("contains requires an object"); +}); +test("should throw an error when the value passed is number", () => { + expect(() => contains(7)).toThrow("contains requires an object"); +}); +test("should throw an error when there is no argument", () => { + expect(() => contains()).toThrow("contains requires an object"); }); From 74bd5bcefaea069cd35316092bda50b091a8d097 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 9 Nov 2026 00:18:09 +0000 Subject: [PATCH 17/53] added a test that wold return empty objects when given empty array --- Sprint-2/implement/lookup.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 547e06c5a7..63e38a8ad5 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -33,3 +33,6 @@ It should return: 'CA': 'CAD' } */ +test("should return an empty object key from an empty array ", () => { + expect(createLookup([])).toEqual({}); +}); From 409fe5afd25bf40e029c11a0d783d2582798ac18 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 9 Nov 2026 00:19:36 +0000 Subject: [PATCH 18/53] declared and initialized variables. added a return value just to pass the test.test passed --- Sprint-2/implement/lookup.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index a6746e07f5..cf6fca184b 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,5 +1,11 @@ -function createLookup() { - // implementation here +function createLookup(array) { + const Currency = [ + ["US", "USD"], + ["CA", "CAD"], + ]; + const countryCurrency = {}; + + return {}; } module.exports = createLookup; From 5623be9064deb6b7390e4303120c02b5e3976abb Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 9 Nov 2026 00:30:02 +0000 Subject: [PATCH 19/53] added a test for on value of an array. test failed --- Sprint-2/implement/lookup.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 63e38a8ad5..303a38373c 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -36,3 +36,6 @@ It should return: test("should return an empty object key from an empty array ", () => { expect(createLookup([])).toEqual({}); }); +test("should return an object key value pairs from an array of one country currency code ", () => { + expect(createLookup(["USD"])).toEqual({ US: "USD" }); +}); From 6101574312f71f4c069329ee933c6cae48909eda Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 9 Nov 2026 00:30:34 +0000 Subject: [PATCH 20/53] added the cod to make the test pass.test passed --- Sprint-2/implement/lookup.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index cf6fca184b..b0cd8dfff4 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,11 +1,15 @@ function createLookup(array) { - const Currency = [ + const currency = [ ["US", "USD"], ["CA", "CAD"], ]; const countryCurrency = {}; - - return {}; + if (array.length == 0) { + return {}; + } else { + countryCurrency[currency[0][0]] = array[0]; + return countryCurrency; + } } module.exports = createLookup; From a117269f9f4e60d22fb1a36b6a8b3ee6252911f5 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 9 Nov 2026 10:39:58 +0000 Subject: [PATCH 21/53] added a test that returnan objectkey value pairs from an array of three/multipple --- Sprint-2/implement/lookup.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 303a38373c..5f904ce189 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -39,3 +39,13 @@ test("should return an empty object key from an empty array ", () => { test("should return an object key value pairs from an array of one country currency code ", () => { expect(createLookup(["USD"])).toEqual({ US: "USD" }); }); +test("should return an object key value pairs from an array of multiple code pairs", () => { + expect(createLookup(["USD", "CAD"])).toEqual({ US: "USD", CA: "CAD" }); +}); +test("should return an object key value pairs from an array of three code pairs", () => { + expect(createLookup(["NAK", "CAD", "EUR"])).toEqual({ + ERI: "NAK", + CA: "CAD", + EU: "EUR", + }); +}); From 5cb83102e63956f4dc3af8f2b82b35c40566b502 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 9 Nov 2026 10:43:06 +0000 Subject: [PATCH 22/53] addeda a code that would allow a search in the given array to much the currency --- Sprint-2/implement/lookup.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index b0cd8dfff4..53dc97af56 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,15 +1,22 @@ function createLookup(array) { const currency = [ + ["EU", "EUR"], ["US", "USD"], ["CA", "CAD"], + ["ERI", "NAK"], ]; const countryCurrency = {}; if (array.length == 0) { return {}; } else { - countryCurrency[currency[0][0]] = array[0]; + for (let i = 0; i < currency.length; i++) { + for (let j = 0; j < currency.length; j++) { + if (currency[i][1] === array[j]) { + countryCurrency[currency[i][0]] = array[j]; + } + } + } return countryCurrency; } } - module.exports = createLookup; From 7b4ff8f5501f0598edc5f4a09ff2731bf6917794 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 9 Nov 2026 20:11:31 +0000 Subject: [PATCH 23/53] made a change on the coding and two tests passed --- Sprint-2/implement/querystring.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 45ec4e5f37..53399af0ea 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -6,7 +6,8 @@ function parseQueryString(queryString) { const keyValuePairs = queryString.split("&"); for (const pair of keyValuePairs) { - const [key, value] = pair.split("="); + const [key, ...rest] = pair.split("="); + const value = rest.join("="); queryParams[key] = value; } From 13ec1b173a24f98ba0f5375fb41895dc7d988ea1 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 15:06:48 +0000 Subject: [PATCH 24/53] added some more code to decode the encoded values and keys.test passed --- Sprint-2/implement/querystring.js | 12 +++++++++++- Sprint-2/implement/querystring.test.js | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 53399af0ea..474e3c5cb5 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -8,7 +8,17 @@ function parseQueryString(queryString) { for (const pair of keyValuePairs) { const [key, ...rest] = pair.split("="); const value = rest.join("="); - queryParams[key] = value; + const keyDecode = decodeURIComponent(key); + const valueDecode = decodeURIComponent(value); + queryParams[keyDecode] = valueDecode; + if ( + key == "key1" && + value == "value1" && + key == "key2" && + value == "value2" + ) { + return queryParams; + } } return queryParams; diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 328b8df617..e9e0e9abd7 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -3,7 +3,7 @@ // Below are some test cases the implementation doesn't handle well. // Fix the implementation for these tests, 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("should parse values containing '='", () => { expect(parseQueryString("equation=a=b-2")).toEqual({ From c91022e72acedb106803c8ad3d4a3582ba62a602 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 16:28:25 +0000 Subject: [PATCH 25/53] added a code to replace ' +' to ' ' .it worked test pass --- Sprint-2/implement/querystring.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 474e3c5cb5..17d0a2590c 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -1,8 +1,10 @@ function parseQueryString(queryString) { const queryParams = {}; + if (queryString.length === 0) { return queryParams; } + const keyValuePairs = queryString.split("&"); for (const pair of keyValuePairs) { @@ -10,18 +12,17 @@ function parseQueryString(queryString) { const value = rest.join("="); const keyDecode = decodeURIComponent(key); const valueDecode = decodeURIComponent(value); - queryParams[keyDecode] = valueDecode; - if ( - key == "key1" && - value == "value1" && - key == "key2" && - value == "value2" - ) { - return queryParams; + let keyDecodeWithout = keyDecode; + let valueDecodeWithout = valueDecode; + if (keyDecode.includes("+")) { + keyDecodeWithout = keyDecode.replace("+", " "); } - } + if (valueDecode.includes("+")) { + valueDecodeWithout = valueDecode.replace("+", " "); + } + queryParams[keyDecodeWithout] = valueDecodeWithout; - return queryParams; + return queryParams; + } } - module.exports = parseQueryString; From b36b46c60ecc65f3a07ae7d7d2ac08da13a239a7 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 16:39:47 +0000 Subject: [PATCH 26/53] added a code to ignore an empty key valu pair after &. it worked .test passed --- Sprint-2/implement/querystring.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 17d0a2590c..634bc74f09 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -8,6 +8,9 @@ function parseQueryString(queryString) { const keyValuePairs = queryString.split("&"); for (const pair of keyValuePairs) { + if (!pair) { + continue; + } const [key, ...rest] = pair.split("="); const value = rest.join("="); const keyDecode = decodeURIComponent(key); @@ -21,8 +24,8 @@ function parseQueryString(queryString) { valueDecodeWithout = valueDecode.replace("+", " "); } queryParams[keyDecodeWithout] = valueDecodeWithout; - - return queryParams; } + return queryParams; } + module.exports = parseQueryString; From cbf65e007232626afa9bf08deb4e1a7982c2075f Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 16:46:02 +0000 Subject: [PATCH 27/53] added a test that returns empty object when empty array is given.test failed --- Sprint-2/implement/tally.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index ca763c2965..a4d4cf291f 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -24,6 +24,9 @@ const tally = require("./tally.js"); // When passed to tally // Then it should return an empty object test.todo("tally on an empty array returns an empty object"); +test(" should return an empty object when empty array is given", () => { + expect(tally([])).toEqual({}); +}); // Given an array with duplicate items // When passed to tally From 0c1d9b3ca0d1e1e00e37dfb7247e409eae036dc5 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 16:48:10 +0000 Subject: [PATCH 28/53] added a code to pass the test.test passed --- Sprint-2/implement/tally.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index f47321812e..011b683a86 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,3 +1,5 @@ -function tally() {} +function tally() { + return {}; +} module.exports = tally; From bb13213e9bf9cf37caef2d0280e954a3e511eb72 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 20:06:11 +0000 Subject: [PATCH 29/53] added a test to return an object containg the count of one item --- Sprint-2/implement/tally.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index a4d4cf291f..2bca24a19d 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -19,6 +19,11 @@ 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("should return an object containing the count for each unique item", () => { + const array = ["a"]; + const countArray = tally(array); + expect(countArray).toEqual({ a: 1 }); +}); // Given an empty array // When passed to tally From d399dd13a1784617d8ef2d4bb627e01acbebc3c4 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 20:10:51 +0000 Subject: [PATCH 30/53] added a code to pass the test to count one lement in an array.test passed --- Sprint-2/implement/tally.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 011b683a86..82bc62ffea 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,5 +1,12 @@ -function tally() { - return {}; +function tally(arrayItems) { + const countItem = {}; + if (arrayItems.length === 1) { + countItem[arrayItems[0]] = arrayItems.length; + return countItem; + } + if (arrayItems.length === 0) { + return countItem; + } } module.exports = tally; From af3f0ebabf03327d279d64b874f449a40155d593 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 20:21:13 +0000 Subject: [PATCH 31/53] added a test for multiple same item and test failed --- Sprint-2/implement/tally.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 2bca24a19d..94fe9dfa1a 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -36,7 +36,11 @@ test(" should return an empty object when empty array is given", () => { // Given an array with duplicate items // When passed to tally // Then it should return counts for each unique item - +test("should return an object containing the count for each unique item", () => { + const array = ["a", "a", "a"]; + const countArray = tally(array); + expect(countArray).toEqual({ a: 3 }); +}); // Given an invalid input like a string, a number, or no argument at all // When passed to tally // Then it should throw Error("tally requires an array") From 9907a225a7d4219d5bc39945884f652928326091 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 20:21:50 +0000 Subject: [PATCH 32/53] changed the equal sign to greater to accomodate multiple items.test passed --- Sprint-2/implement/tally.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 82bc62ffea..ea34172cca 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,6 +1,6 @@ function tally(arrayItems) { const countItem = {}; - if (arrayItems.length === 1) { + if (arrayItems.length >= 1) { countItem[arrayItems[0]] = arrayItems.length; return countItem; } From 2aac822623505fd313c06a19ef94f0bb04c02cd9 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 21:11:39 +0000 Subject: [PATCH 33/53] added a tests for multiple items and test that throws error when given an invalid input .test failed --- Sprint-2/implement/tally.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 94fe9dfa1a..3ba844edb2 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -41,6 +41,21 @@ test("should return an object containing the count for each unique item", () => const countArray = tally(array); expect(countArray).toEqual({ a: 3 }); }); +test("should return an object containing the count for each unique item", () => { + const array = ["a", "a", "b", "b", "b", "c"]; + const countArray = tally(array); + expect(countArray).toEqual({ a: 2, b: 3, c: 1 }); +}); + // Given an invalid input like a string, a number, or no argument at all // When passed to tally // Then it should throw Error("tally requires an array") +test("should throw an error when given invalid input:string", () => { + (expect(() => tally("a")), toThrow("tally rquires an input")); +}); +test("should throw an error when given invalid input:number", () => { + (expect(() => tally(5)), toThrow("tally rquires an input")); +}); +test("should throw an error when given invalid input: no argument", () => { + (expect(() => tally()), toThrow("tally rquires an input")); +}); From f0eefc8549a347dfc07ecf009ce4acc76c96ffa1 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 21:12:37 +0000 Subject: [PATCH 34/53] added a code to count the items .test passed --- Sprint-2/implement/tally.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index ea34172cca..88e528cd24 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,12 +1,21 @@ function tally(arrayItems) { const countItem = {}; - if (arrayItems.length >= 1) { - countItem[arrayItems[0]] = arrayItems.length; + + if (arrayItems.length === 0) { return countItem; } - if (arrayItems.length === 0) { + + if (arrayItems.length === 1) { + countItem[arrayItems[0]] = arrayItems.length; return countItem; } + for (const item of arrayItems) { + if (countItem[item]) { + countItem[item] += 1; + } else { + countItem[item] = 1; + } + } + return countItem; } - module.exports = tally; From c04e5e6386e0814a6f29c4bac2cb890ffcc7fe22 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 21:22:16 +0000 Subject: [PATCH 35/53] added a code to throw error and test passed --- Sprint-2/implement/tally.js | 3 +++ Sprint-2/implement/tally.test.js | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 88e528cd24..4604449886 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,5 +1,8 @@ function tally(arrayItems) { const countItem = {}; + if (!Array.isArray(arrayItems)) { + throw new Error("tally rquires an input"); + } if (arrayItems.length === 0) { return countItem; diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 3ba844edb2..be4762ab59 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -51,11 +51,11 @@ test("should return an object containing the count for each unique item", () => // When passed to tally // Then it should throw Error("tally requires an array") test("should throw an error when given invalid input:string", () => { - (expect(() => tally("a")), toThrow("tally rquires an input")); + expect(() => tally("a")).toThrow("tally rquires an input"); }); test("should throw an error when given invalid input:number", () => { - (expect(() => tally(5)), toThrow("tally rquires an input")); + expect(() => tally(5)).toThrow("tally rquires an input"); }); test("should throw an error when given invalid input: no argument", () => { - (expect(() => tally()), toThrow("tally rquires an input")); + expect(() => tally()).toThrow("tally rquires an input"); }); From c25069487f418d59159de3b9e2f51c74d4646eb0 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 21:25:57 +0000 Subject: [PATCH 36/53] refractored the code --- Sprint-2/implement/tally.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 4604449886..ad07d973e3 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -3,15 +3,6 @@ function tally(arrayItems) { if (!Array.isArray(arrayItems)) { throw new Error("tally rquires an input"); } - - if (arrayItems.length === 0) { - return countItem; - } - - if (arrayItems.length === 1) { - countItem[arrayItems[0]] = arrayItems.length; - return countItem; - } for (const item of arrayItems) { if (countItem[item]) { countItem[item] += 1; From 43f3f65759e02b9c91ff26041506111659b58143 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 10 Nov 2026 21:39:00 +0000 Subject: [PATCH 37/53] answered a nd b --- Sprint-2/interpret/invert.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index bb353fb1fd..4f906e688c 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -15,11 +15,15 @@ function invert(obj) { 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} // c) What does Object.entries return? Why is it needed in this program? From 5249da4a0a54c33b5bae120adf41dae8df76f4a6 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Wed, 11 Nov 2026 09:23:54 +0000 Subject: [PATCH 38/53] answered question C --- 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 4f906e688c..74b1b1cbe5 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -25,7 +25,7 @@ console.log(invert({ 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? // d) Explain why the current return value is different from the target output From a96ef2d4bf6bfa57f594e164aa0702f7c7b9087f Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Wed, 11 Nov 2026 09:48:01 +0000 Subject: [PATCH 39/53] answerd question d and e --- Sprint-2/interpret/invert.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index 74b1b1cbe5..bfdb9fa4f5 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -17,17 +17,27 @@ function invert(obj) { } console.log(invert({ a: 1, b: 2 })); // a) What is the current return value when invert is called with { a : 1 } -{ - key: 1; -} + +//{key: 1;} + // b) What is the current return value when invert is called with { a: 1, b: 2 } -{ - key: 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? -// d) Explain why the current return value is different from the target output +//{'1' :'a','2':'b' } + +// d) What does Object.entries return? Why is it needed in this program? + +//Objet.entries takes objects and returne array with in array or sub arrays. +//in this program it is needed to put the properties in an array as key and value. +// After that line though, the next line takes the key and value and place it in an object again by changing key and value +// position when stored in the object + +// e) Explain why the current return value is different from the target output +//The crrent output is different becouse it is only storing the last element in the loop +// with the key name "key" . So when it is printed out it comes forexample {'key': 1} +//and also the value and key dont change position. -// e) Fix the implementation of invert (and write tests to prove it's fixed!) +// f) Fix the implementation of invert (and write tests to prove it's fixed!) From f1633062bfae771f65cb4982154a5b225886c8b7 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Wed, 11 Nov 2026 09:51:23 +0000 Subject: [PATCH 40/53] fixed the implementation now it is printing out the target values --- Sprint-2/interpret/invert.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index bfdb9fa4f5..b3e12a5f4c 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -10,7 +10,7 @@ function invert(obj) { const invertedObj = {}; for (const [key, value] of Object.entries(obj)) { - invertedObj.key = value; + invertedObj[value] = key; } return invertedObj; @@ -41,3 +41,5 @@ console.log(invert({ a: 1, b: 2 })); //and also the value and key dont change position. // f) Fix the implementation of invert (and write tests to prove it's fixed!) + +// fixed the implementation and now it is printing the target value From 276e30c555130252ec067c3b978fa338174d911d Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Wed, 11 Nov 2026 10:07:45 +0000 Subject: [PATCH 41/53] added the export to the function --- 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 b3e12a5f4c..7740e596d9 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -15,7 +15,7 @@ function invert(obj) { return invertedObj; } -console.log(invert({ a: 1, b: 2 })); +module.exports = invert; // a) What is the current return value when invert is called with { a : 1 } //{key: 1;} From 9c2fa1dfb2e12cee4a678a52b54c2e05c74b9c83 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Wed, 11 Nov 2026 10:10:00 +0000 Subject: [PATCH 42/53] created te file for testing and imported the function invert fron invert.js --- Sprint-2/interpret/invert.test.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 Sprint-2/interpret/invert.test.js diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js new file mode 100644 index 0000000000..301e6d2f2f --- /dev/null +++ b/Sprint-2/interpret/invert.test.js @@ -0,0 +1 @@ +const invert = require("./invert.js"); From 4513817f5a1719eae1bbb6785594ec5dd8b042cd Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Wed, 11 Nov 2026 10:19:25 +0000 Subject: [PATCH 43/53] added a test when given empty object to return empty object .test passed --- Sprint-2/interpret/invert.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 301e6d2f2f..5adabc2522 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -1 +1,5 @@ const invert = require("./invert.js"); +// for +test(" should return an empty object if given empty object", () => { + expect(invert({})).toEqual({}); +}); From a05704ca6f7a7672300553b52252d7a91796afc8 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Wed, 11 Nov 2026 10:48:00 +0000 Subject: [PATCH 44/53] added a test for one and more properties and test passed --- Sprint-2/interpret/invert.test.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 5adabc2522..49f4e9623d 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -1,5 +1,14 @@ const invert = require("./invert.js"); -// for +// for an empty object test(" should return an empty object if given empty object", () => { expect(invert({})).toEqual({}); }); +//test for one proprty in an object +test(" should return an empty object if given empty object", () => { + expect(invert({ a: 1 })).toEqual({ 1: "a" }); +}); +//test for two property in an object +test(" should return an empty object if given empty object", () => { + expect(invert({ a: 1, b: 2, c: 3 })).toEqual({ 1: "a", 2: "b", 3: "c" }); +}); +// From 5d5fb7e8ee42c9c9c514d49475465189b596773e Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Wed, 11 Nov 2026 18:12:58 +0000 Subject: [PATCH 45/53] added a test to show that "first+name=Mary+Jane" can pass the test .test passed --- Sprint-2/implement/querystring.test.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index e9e0e9abd7..22b0db772b 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -37,12 +37,18 @@ test("should replace '+' by ' '", () => { }); }); +test("should replace '+' by ' '", () => { + expect(parseQueryString("first+name=Mary+Jane")).toEqual({ + "first name": "Mary Jane", + }); +}); + // Stretch exercise: Handling query strings that contain identical keys // Delete this test if you are not working on this optional case -test("should store values of a key in an array when the key has 2 or more values", () => { - expect(parseQueryString("key=value1&key=value2&key=value3&foo=bar")).toEqual({ - key: ["value1", "value2", "value3"], - foo: "bar", - }); -}); +//test("should store values of a key in an array when the key has 2 or more values", () => { +// expect(parseQueryString("key=value1&key=value2&key=value3&foo=bar")).toEqual({ +// key: ["value1", "value2", "value3"], +// foo: "bar", +//}); +//}); From e03d59d3f7269e4e6192050c428c644801629f02 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Wed, 11 Nov 2026 21:04:10 +0000 Subject: [PATCH 46/53] edited the code as advised now it takes the array from the input .all test pass --- Sprint-2/implement/lookup.js | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index 53dc97af56..e82678829e 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,22 +1,10 @@ function createLookup(array) { - const currency = [ - ["EU", "EUR"], - ["US", "USD"], - ["CA", "CAD"], - ["ERI", "NAK"], - ]; const countryCurrency = {}; - if (array.length == 0) { - return {}; - } else { - for (let i = 0; i < currency.length; i++) { - for (let j = 0; j < currency.length; j++) { - if (currency[i][1] === array[j]) { - countryCurrency[currency[i][0]] = array[j]; - } - } - } - return countryCurrency; + + for (let i = 0; i < array.length; i++) { + countryCurrency[array[i][0]] = array[i][1]; } + return countryCurrency; } + module.exports = createLookup; From cc041a1c9f3d77be544890610c179b790884e83b Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Wed, 11 Nov 2026 21:04:59 +0000 Subject: [PATCH 47/53] made changes to this file as well,all test pass --- Sprint-2/implement/lookup.test.js | 22 +++++++++++++++++----- Sprint-2/implement/querystring.js | 7 ++++--- Sprint-2/implement/querystring.test.js | 5 +++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 5f904ce189..ae25412c64 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -1,7 +1,5 @@ const createLookup = require("./lookup.js"); -test.todo("creates a country currency code lookup for multiple codes"); - /* Create a lookup object of key value pairs from an array of code pairs @@ -37,13 +35,27 @@ test("should return an empty object key from an empty array ", () => { expect(createLookup([])).toEqual({}); }); test("should return an object key value pairs from an array of one country currency code ", () => { - expect(createLookup(["USD"])).toEqual({ US: "USD" }); + expect(createLookup([["US", "USD"]])).toEqual({ US: "USD" }); }); test("should return an object key value pairs from an array of multiple code pairs", () => { - expect(createLookup(["USD", "CAD"])).toEqual({ US: "USD", CA: "CAD" }); + expect( + createLookup([ + ["US", "USD"], + ["CA", "CAD"], + ]) + ).toEqual({ + US: "USD", + CA: "CAD", + }); }); test("should return an object key value pairs from an array of three code pairs", () => { - expect(createLookup(["NAK", "CAD", "EUR"])).toEqual({ + expect( + createLookup([ + ["ERI", "NAK"], + ["CA", "CAD"], + ["EU", "EUR"], + ]) + ).toEqual({ ERI: "NAK", CA: "CAD", EU: "EUR", diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 634bc74f09..ce0dd74595 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -17,9 +17,10 @@ function parseQueryString(queryString) { const valueDecode = decodeURIComponent(value); let keyDecodeWithout = keyDecode; let valueDecodeWithout = valueDecode; - if (keyDecode.includes("+")) { - keyDecodeWithout = keyDecode.replace("+", " "); - } + if (keydecode) + if (keyDecode.includes("+")) { + keyDecodeWithout = keyDecode.replace("+", " "); + } if (valueDecode.includes("+")) { valueDecodeWithout = valueDecode.replace("+", " "); } diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 22b0db772b..49a7ef8e7b 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -37,6 +37,11 @@ test("should replace '+' by ' '", () => { }); }); +test("should replace '+' by ' '", () => { + expect(parseQueryString("first+name=Mary+Jane")).toEqual({ + "first name": "Mary Jane", + }); +}); test("should replace '+' by ' '", () => { expect(parseQueryString("first+name=Mary+Jane")).toEqual({ "first name": "Mary Jane", From 3afcdc43da2248af17331e7613c754fd69580136 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 14 Nov 2026 02:03:44 +0000 Subject: [PATCH 48/53] made changes to the code as advised all 6 test passed --- Sprint-2/implement/querystring.js | 24 +++++++++++------------- Sprint-2/implement/querystring.test.js | 5 ----- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index ce0dd74595..4e6d1521d1 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -11,20 +11,18 @@ function parseQueryString(queryString) { if (!pair) { continue; } - const [key, ...rest] = pair.split("="); - const value = rest.join("="); - const keyDecode = decodeURIComponent(key); - const valueDecode = decodeURIComponent(value); - let keyDecodeWithout = keyDecode; - let valueDecodeWithout = valueDecode; - if (keydecode) - if (keyDecode.includes("+")) { - keyDecodeWithout = keyDecode.replace("+", " "); - } - if (valueDecode.includes("+")) { - valueDecodeWithout = valueDecode.replace("+", " "); + let [key, ...rest] = pair.split("="); + let value = rest.join("="); + + const lastThreeCharKey = key.slice(-3); + if (!lastThreeCharKey.includes("+") || key.includes("%")) { + key = decodeURIComponent(key.replace("+", " ")); + } + const lastThreeCharVal = value.slice(-3); + if (!lastThreeCharVal.includes("+")) { + value = decodeURIComponent(value.replace("+", " ")); } - queryParams[keyDecodeWithout] = valueDecodeWithout; + queryParams[key] = value; } return queryParams; } diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 49a7ef8e7b..22b0db772b 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -37,11 +37,6 @@ test("should replace '+' by ' '", () => { }); }); -test("should replace '+' by ' '", () => { - expect(parseQueryString("first+name=Mary+Jane")).toEqual({ - "first name": "Mary Jane", - }); -}); test("should replace '+' by ' '", () => { expect(parseQueryString("first+name=Mary+Jane")).toEqual({ "first name": "Mary Jane", From f162460680c67f8e4386cf5f948cce770e6dd497 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 14 Nov 2026 02:07:11 +0000 Subject: [PATCH 49/53] made the correction --- 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 61e747b5dc..53b92bd536 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,6 +1,6 @@ // Predict and explain first... -// my prediction is that this is not indexed array. it is an array that uses key. +// my prediction is that this is not indexed array. it is an object that uses key. // This code should log out the houseNumber from the address object // but it isn't working... From 1b17717e82cbfea85e92837a775c94d35517881e Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 14 Nov 2026 02:19:39 +0000 Subject: [PATCH 50/53] made changes to the test names --- Sprint-2/interpret/invert.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 49f4e9623d..64587c0d88 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -4,11 +4,11 @@ test(" should return an empty object if given empty object", () => { expect(invert({})).toEqual({}); }); //test for one proprty in an object -test(" should return an empty object if given empty object", () => { +test(" should return an object inverted when given one property object", () => { expect(invert({ a: 1 })).toEqual({ 1: "a" }); }); //test for two property in an object -test(" should return an empty object if given empty object", () => { +test(" should return an object that is inverted when given two property object", () => { expect(invert({ a: 1, b: 2, c: 3 })).toEqual({ 1: "a", 2: "b", 3: "c" }); }); // From a7b8c0de85cca8635c252e37b5b641426c6c1296 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 14 Nov 2026 02:21:22 +0000 Subject: [PATCH 51/53] made small changes --- Sprint-2/debug/author.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 0f30db890b..eb6e122d7a 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,13 +1,13 @@ // Predict and explain first... -// my prediction here is that we can not use for..of loop because author is not iterable. +// my prediction here is that we can not use for..of loop because author is an object. // The reason is, it doesnt use indices it uses keys.instead we will use for..in loop. // 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 // As I said earlier it is not using index, we can not iterate it with -// for ..of loop. The output also gonna be the key so we have to change that as well. +// for ..of loop. The output also going to be the key so we have to change that as well. const author = { firstName: "Zadie", From a6c4e317952d92a99439a1a74b8af445abea1581 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 14 Nov 2026 20:58:55 +0000 Subject: [PATCH 52/53] add a test to replace all the '+' sign , test failed --- Sprint-2/implement/querystring.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 22b0db772b..e8aecb2015 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -43,6 +43,13 @@ test("should replace '+' by ' '", () => { }); }); +test("should replace multiple plus'+' by ' '", () => { + expect(parseQueryString("name=John+Doe+Foo&age=30&city=New+York")).toEqual({ + name: "John Doe Foo", + age: "30", + city: "New York", + }); +}); // Stretch exercise: Handling query strings that contain identical keys // Delete this test if you are not working on this optional case From 7828f7ba259de2ea1ed69698692e980a97da62ea Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 14 Nov 2026 20:59:55 +0000 Subject: [PATCH 53/53] changed a code to make the test that should replave all the + sign to " ".test passed --- Sprint-2/implement/querystring.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 4e6d1521d1..4aa150e837 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -14,13 +14,13 @@ function parseQueryString(queryString) { let [key, ...rest] = pair.split("="); let value = rest.join("="); - const lastThreeCharKey = key.slice(-3); + const lastThreeCharKey = key.slice(-2); if (!lastThreeCharKey.includes("+") || key.includes("%")) { - key = decodeURIComponent(key.replace("+", " ")); + key = decodeURIComponent(key.replaceAll("+", " ")); } - const lastThreeCharVal = value.slice(-3); + const lastThreeCharVal = value.slice(-2); if (!lastThreeCharVal.includes("+")) { - value = decodeURIComponent(value.replace("+", " ")); + value = decodeURIComponent(value.replaceAll("+", " ")); } queryParams[key] = value; }