From 14a2f59166995ae34054a984268fa4aefa8654d7 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 4 Mar 2026 00:28:16 +0000 Subject: [PATCH 01/22] Fixed object property access using dot notation + added prediction and explanation --- Sprint-2/debug/address.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 940a6af83..26d8baaf8 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,4 +1,8 @@ // Predict and explain first... +// address is an object, not an array +// address[0] looks for a property named "0", +// which doesn't exist → returns undefined +// So the log will say: My house number is undefined // This code should log out the houseNumber from the address object // but it isn't working... @@ -12,4 +16,4 @@ const address = { postcode: "XYZ 123", }; -console.log(`My house number is ${address[0]}`); +console.log(`My house number is ${address.houseNumber}`); From ebab27d8efb8867db20aca08edafac3a4c208380 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 4 Mar 2026 00:34:54 +0000 Subject: [PATCH 02/22] Fixed non-iterable object with Object.values + added prediction and explanation --- 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 8c2125977..3252f748d 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,4 +1,7 @@ // Predict and explain first... +// for..of requires an iterable, like arrays or strings +// Plain objects are not iterable → throws TypeError: author is not iterable +// Nothing gets logged. // 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,6 @@ const author = { alive: true, }; -for (const value of author) { +for (const value of Object.values(author)) { console.log(value); } From af62090dbe252defccdc6404e350783db2b5b6c2 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 4 Mar 2026 21:23:24 +0000 Subject: [PATCH 03/22] Fixed object interpolation, loop ingredients + added prediction and explanation --- Sprint-2/debug/recipe.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cd..538cf16e1 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,4 +1,6 @@ // Predict and explain first... +// ${recipe} in template literal becomes "[object Object]" (not useful) +// No loop to print each ingredient on a new line // This program should log out the title, how many it serves and the ingredients. // Each ingredient should be logged on a new line @@ -10,6 +12,9 @@ const recipe = { ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title} serves ${recipe.serves} - ingredients: -${recipe}`); +console.log(`${recipe.title} serves ${recipe.serves}`); +console.log(" ingredients:"); + +for (const ing of recipe.ingredients) { + console.log(` - ${ing}`); +} From 4c8181ec06fae84eddf98b56fd84ab737c84aa45 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 4 Mar 2026 21:35:43 +0000 Subject: [PATCH 04/22] Updated my prediction and explanation for this problem --- Sprint-2/debug/author.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 3252f748d..5ad5a90b0 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,7 +1,8 @@ // Predict and explain first... -// for..of requires an iterable, like arrays or strings -// Plain objects are not iterable → throws TypeError: author is not iterable -// Nothing gets logged. +// The 'author' variable is an object, not an array or string. +// for..of loops require an iterable, but plain objects are not iterable. +// This will throw a TypeError: author is not iterable. +// Nothing will be logged to the console. // 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 e5a0167e48f5e77c9153a03de87236f23137fd11 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 4 Mar 2026 21:39:22 +0000 Subject: [PATCH 05/22] Updated the prediciton and explanation of this problem --- Sprint-2/debug/recipe.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 538cf16e1..206b435fc 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,6 +1,8 @@ // Predict and explain first... -// ${recipe} in template literal becomes "[object Object]" (not useful) -// No loop to print each ingredient on a new line +// The template literal ${recipe} attempts to convert the entire object to a string. +// Because objects aren't strings, it will log: "[object Object]". +// It also fails to access the specific 'ingredients' array or loop through them. +// The result will be one confusing line instead of a formatted list. // This program should log out the title, how many it serves and the ingredients. // Each ingredient should be logged on a new line From 461e87e68c6f746785b8b606c10b41097a31ae0b Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 4 Mar 2026 22:58:28 +0000 Subject: [PATCH 06/22] Added tests for contains function --- Sprint-2/implement/contains.test.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 326bdb1f2..3702043d1 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -16,20 +16,40 @@ 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("returns true when the property exists in the object", () => { + expect(contains({ a: 1, b: 2 }, "a")).toBe(true); + expect(contains({ a: 1, b: 2 }, "b")).toBe(true); +}); // 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", () => { + expect(contains({}, "a")).toBe(false); + expect(contains({}, "toString")).toBe(false); +}); // Given an object with properties // When passed to contains with an existing property name // Then it should return true +test("returns true for existing property name", () => { + expect(contains({ name: "Alex" }, "name")).toBe(true); + expect(contains({ id: 42 }, "id")).toBe(true); +}); // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false +test("returns false for non-existent property name", () => { + expect(contains({ name: "Alex", age: 42 }, "email")).toBe(false); + expect(contains({ age: 54 }, "name")).toBe(false); +}); // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error +test("handles invalid parameters like an array", () => { + expect(contains([], "length")).toBe(false); + expect(contains(123, "length")).toBe(false); + expect(contains("string", "length")).toBe(false); +}); From 371eb7e23da7ae8e7ff8d0640fbd8be9c631efaf Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 4 Mar 2026 23:13:56 +0000 Subject: [PATCH 07/22] Added contains.js implementation --- Sprint-2/implement/contains.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a..d6278dbb5 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,12 @@ -function contains() {} +function contains(object, propertyName) { + // return false if object is null/defined or not an object + if (object == null) return false; + // typeof check + reject arrays + if (typeof object !== "object") return false; + if (Array.isArray(object)) return false; + + // Use hasOwnProperty to check only own properties + return Object.prototype.hasOwnProperty.call(object, propertyName); +} module.exports = contains; From 21e1adcd2dcce465a2d2042c691d3edb4ab40182 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 4 Mar 2026 23:34:12 +0000 Subject: [PATCH 08/22] Added tests for the lookup function --- Sprint-2/implement/lookup.test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 547e06c5a..6cdc0f61d 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -1,6 +1,17 @@ const createLookup = require("./lookup.js"); -test.todo("creates a country currency code lookup for multiple codes"); +test("creates a country currency code lookup for multiple codes", () => { + const pairs = [ + ["US", "USD"], + ["CA", "CAD"], + ]; + const result = createLookup(pairs); + + expect(result).toEqual({ + US: "USD", + CA: "CAD", + }); +}); /* From 9e7a052695ff7a177ae1b1477642844751367d04 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Wed, 4 Mar 2026 23:51:18 +0000 Subject: [PATCH 09/22] Implemented lookup.js function --- Sprint-2/implement/lookup.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index a6746e07f..8c4747e31 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,5 +1,16 @@ -function createLookup() { +function createLookup(pairs) { // implementation here + // Creates empty object that will store our, + // country → currency + const lookup = {}; + // Loop through each pair in the input array + for (const [country, currency] of pairs) { + // Use the country code as they key + // Assigns the correspoding currency code as the value + lookup[country] = currency; + } + // returns the completed lookup object + return lookup; } module.exports = createLookup; From 5bd4e7e5ea5adece2f66405184e556fa66d9993c Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sat, 7 Mar 2026 04:51:17 +0000 Subject: [PATCH 10/22] Fixed parseQueryString value parsing + filter empty pairs --- Sprint-2/implement/querystring.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 45ec4e5f3..336cf7ca2 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -1,13 +1,29 @@ function parseQueryString(queryString) { const queryParams = {}; - if (queryString.length === 0) { + + // Handle empty string or just "?" + if (!queryString || queryString === "?") { return queryParams; } - const keyValuePairs = queryString.split("&"); + + // Remove leading ? if present + const cleaned = queryString.startsWith("?") + ? queryString.slice(1) + : queryString; + const keyValuePairs = cleaned.split("&").filter(Boolean); for (const pair of keyValuePairs) { - const [key, value] = pair.split("="); - queryParams[key] = value; + // Only split on the first = + const equalIndex = pair.indexOf("="); + + if (equalIndex === -1) { + // key without = → value is empty string + queryParams[pair] = ""; + } else { + const key = pair.slice(0, equalIndex); + const value = pair.slice(equalIndex + 1); + queryParams[key] = value; + } } return queryParams; From 6b31d1dc688b4c9d2f43425de2732552be7832ff Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sat, 7 Mar 2026 06:04:51 +0000 Subject: [PATCH 11/22] fix: split on first = only to correctly parse values containing = --- Sprint-2/implement/querystring.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 336cf7ca2..22ee0f3c9 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -10,18 +10,18 @@ function parseQueryString(queryString) { const cleaned = queryString.startsWith("?") ? queryString.slice(1) : queryString; - const keyValuePairs = cleaned.split("&").filter(Boolean); - - for (const pair of keyValuePairs) { - // Only split on the first = - const equalIndex = pair.indexOf("="); - - if (equalIndex === -1) { - // key without = → value is empty string - queryParams[pair] = ""; - } else { - const key = pair.slice(0, equalIndex); - const value = pair.slice(equalIndex + 1); + + // Split into segments and ignore empty ones + const segments = cleaned.split("&").filter(Boolean); + + for (const segment of segments) { + // Split only on the first =, but everything after is a value + const eqIndex = segment.indexOf("="); + + const key = eqIndex === -1 ? segment : segment.slice(0, eqIndex); + const value = eqIndex === -1 ? "" : segment.slice(eqIndex + 1); + + if (key) { queryParams[key] = value; } } From a4b781b3ac7c1018ec4e6b75d4d65c070c918ced Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sat, 7 Mar 2026 06:06:59 +0000 Subject: [PATCH 12/22] test: added edge case tests for parseQueryString and fixed typo in age value --- Sprint-2/implement/querystring.test.js | 52 +++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 3e218b789..28ab418b6 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -3,10 +3,58 @@ // 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", + }); +}); + +test("handles multiple parameters", () => { + expect(parseQueryString("name=Alex&age=25&city=London")).toEqual({ + name: "Alex", + age: "25", + city: "London", + }); +}); + +test("handles empty value (key=)", () => { + expect(parseQueryString("search=&page=3")).toEqual({ + search: "", + page: "3", + }); +}); + +test("handles key without value", () => { + expect(parseQueryString("debug&sort=asc")).toEqual({ + debug: "", + sort: "asc", + }); +}); + +test("handles leading question mark", () => { + expect(parseQueryString("?q=javascript&lang=en")).toEqual({ + q: "javascript", + lang: "en", + }); +}); + +test("returns empty object when input is empty or just ?", () => { + expect(parseQueryString("")).toEqual({}); + expect(parseQueryString("?")).toEqual({}); +}); + +test("ignores trailing &", () => { + expect(parseQueryString("a=1&b=2&")).toEqual({ + a: "1", + b: "2", + }); +}); + +test("ignores repeated &", () => { + expect(parseQueryString("x=10&&y=20")).toEqual({ + x: "10", + y: "20", }); }); From 8953ba62b021a7433b4e0d0f221f453131ccc772 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sun, 8 Mar 2026 01:09:24 +0000 Subject: [PATCH 13/22] Added implementation for tally --- Sprint-2/implement/tally.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index f47321812..40ba33b9f 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,3 +1,22 @@ -function tally() {} +function tally(arr) { + // Check if the input is not an array + if (!Array.isArray(arr)) { + // If it's not an array, stop the function + // and throw an error message + throw new Error("Input must be an array"); + } + + // Create an empty obkect to store our counts + const counts = {}; + + // Loop through each item in the array one by one + for (const item of arr) { + // If the item already exists in counts, add 1 to it + // If it doesn't exist yet (undefined), start it at 0 then add 1 + counts[item] = (counts[item] || 0) + 1; + } + // Return the finished counts object once all items have been tallied + return counts; +} module.exports = tally; From 17d86417692408a0efce489f1c52b2e2d4197cbb Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sun, 8 Mar 2026 01:10:12 +0000 Subject: [PATCH 14/22] added test cases to reflect the function --- Sprint-2/implement/tally.test.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 2ceffa8dd..55b1eb0a0 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -19,16 +19,42 @@ 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 returns an object containing 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("tally on an empty array returns an empty object", () => { + expect(tally([])).toEqual({}); +}); + +// Given an array with a single item +// When passed to tally +// Then it should return a count of 1 for that item +test("tally on an array with one item returns count of 1", () => { + expect(tally(["a"])).toEqual({ + a: 1, + }); +}); // Given an array with duplicate items // When passed to tally // Then it should return counts for each unique item +test("tally counts duplicate items correctly", () => { + expect(tally(["a", "a", "a"])).toEqual({ + a: 3, + }); +}); // Given an invalid input like a string // When passed to tally // Then it should throw an error +test("tally throws an error for invalid input", () => { + expect(() => tally("abc")).toThrow("Input must be an array"); +}); From 86ed8175a589a0fa595fcb950704416c9cfcb6eb Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sun, 8 Mar 2026 17:59:03 +0000 Subject: [PATCH 15/22] Answered a to d questions --- Sprint-2/interpret/invert.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index bb353fb1f..080302f1f 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -17,13 +17,21 @@ function invert(obj) { } // a) What is the current return value when invert is called with { a : 1 } +// The current return value when invert is called with { a : 1 } is { key:1 } // b) What is the current return value when invert is called with { a: 1, b: 2 } +// The current return value when invert is called with { a: 1, b: 2 } is { key:2 } // c) What is the target return value when invert is called with {a : 1, b: 2} +// The target return value when invert is called with {a : 1, b: 2} is { "1": "a", "2": "b" } // c) What does Object.entries return? Why is it needed in this program? +// Object.entries converts an object into an array of [key, value] pairs, +// it's needed so you can loop through both the key and value at the same time // d) Explain why the current return value is different from the target output +// The bug is invertedObj.key = value - dot notation sets a literal key called "key", +// instead of using the variable. It also overwrites itseld on every loop iteration, +// so you only ever get the last value. // e) Fix the implementation of invert (and write tests to prove it's fixed!) From ddd29d31253842babf004d0028e7367a751d910e Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sun, 8 Mar 2026 18:13:39 +0000 Subject: [PATCH 16/22] Fix: Added missing module.exports to invert --- Sprint-2/interpret/invert.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index 080302f1f..43339c7c9 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -7,15 +7,25 @@ // E.g. invert({x : 10, y : 20}), target output: {"10": "x", "20": "y"} function invert(obj) { + // Check if the input is not an object + if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { + throw new Error("Input must be an object"); + } + const invertedObj = {}; + // Loop through each key value pair and swap them for (const [key, value] of Object.entries(obj)) { - invertedObj.key = value; + // bracket notation uses the variable, + // not the literal string "key" + invertedObj[value] = key; } return invertedObj; } +module.exports = invert; + // a) What is the current return value when invert is called with { a : 1 } // The current return value when invert is called with { a : 1 } is { key:1 } From e604821622a21609edfdfac7426274d85667a93c Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sun, 8 Mar 2026 18:15:18 +0000 Subject: [PATCH 17/22] Answered question e --- Sprint-2/interpret/invert.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index 43339c7c9..8aef1e3f6 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -45,3 +45,4 @@ module.exports = invert; // so you only ever get the last value. // e) Fix the implementation of invert (and write tests to prove it's fixed!) +// Fixed implementation of invert and added tests cases to prove it's fixed. From 846db55e4fc6d51a3a278b783ede0353fb464afe Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sun, 8 Mar 2026 18:15:55 +0000 Subject: [PATCH 18/22] Added test cases for invert.js --- Sprint-2/interpret/invert.test.js | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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 000000000..5d20a9bf9 --- /dev/null +++ b/Sprint-2/interpret/invert.test.js @@ -0,0 +1,34 @@ +const invert = require("./invert.js"); + +// Given an object +// When invert is passed this object +// Then it should swap the keys and values +test("invert swaps the keys and values of an object", () => { + expect(invert({ x: 10, y: 20 })).toEqual({ + 10: "x", + 20: "y", + }); +}); + +// Given an object with one key value pair +// When passed to invert +// Then it should return the swapped pair +test("invert swaps a single key value pair", () => { + expect(invert({ a: 1 })).toEqual({ + 1: "a", + }); +}); + +// Given an empty object +// When passed to invert +// Then it should return an empty object +test("invert on an empty object returns an empty object", () => { + expect(invert({})).toEqual({}); +}); + +// Given an invalid input like an array +// When passed to invert +// Then it should throw an error +test("invert throws an error for invalid input", () => { + expect(() => invert([])).toThrow("Input must be an object"); +}); From cbcbe6424af057acf0d8f270817b6caf45895a50 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Thu, 19 Mar 2026 00:42:21 +0000 Subject: [PATCH 19/22] Fix: Use Object.hasOwn instead of hasOwnProperty --- Sprint-2/implement/contains.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index d6278dbb5..b9205c94f 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -5,8 +5,8 @@ function contains(object, propertyName) { if (typeof object !== "object") return false; if (Array.isArray(object)) return false; - // Use hasOwnProperty to check only own properties - return Object.prototype.hasOwnProperty.call(object, propertyName); + // Use Object.hasOwn to check only own properties + return Object.hasOwn(object, propertyName); } module.exports = contains; From 1962dc24a976d8e0dd1f7090691cf88588d37016 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Thu, 19 Mar 2026 00:50:09 +0000 Subject: [PATCH 20/22] Fix: Use Object.create(null) to avoid inherited property conflicts --- Sprint-2/implement/tally.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 40ba33b9f..1a7460980 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -6,8 +6,9 @@ function tally(arr) { throw new Error("Input must be an array"); } - // Create an empty obkect to store our counts - const counts = {}; + // Create an empty object with no inherited properties + // This prevents conflicts with built in properties like "toString" + const counts = Object.create(null); // Loop through each item in the array one by one for (const item of arr) { From 827f5b3016f5ed82d3833433cffe6ad931eeadf1 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Thu, 19 Mar 2026 01:50:33 +0000 Subject: [PATCH 21/22] Fix: Add more invalid input types to invert tests --- Sprint-2/interpret/invert.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 5d20a9bf9..387573155 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -26,9 +26,13 @@ test("invert on an empty object returns an empty object", () => { expect(invert({})).toEqual({}); }); -// Given an invalid input like an array +// Given an invalid input like an array, string, number, null or undefined // When passed to invert // Then it should throw an error test("invert throws an error for invalid input", () => { expect(() => invert([])).toThrow("Input must be an object"); + expect(() => invert("hello")).toThrow("Input must be an object"); + expect(() => invert(123)).toThrow("Input must be an object"); + expect(() => invert(null)).toThrow("Input must be an object"); + expect(() => invert(undefined)).toThrow("Input must be an object"); }); From 0eebfb8ae5aebdbaed76b728aeda6ce158342530 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Thu, 19 Mar 2026 02:04:34 +0000 Subject: [PATCH 22/22] Fix: Decode percent-encoded keys and values in parseQueryString --- 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 22ee0f3c9..a7433c0e0 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -22,7 +22,8 @@ function parseQueryString(queryString) { const value = eqIndex === -1 ? "" : segment.slice(eqIndex + 1); if (key) { - queryParams[key] = value; + // Decode percent-encoded characters in both key and value + queryParams[decodeURIComponent(key)] = decodeURIComponent(value); } }