From 653f0185d757bb84f57f0d8788d61d9d3951430a Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 10:55:49 +0000 Subject: [PATCH 01/30] Added in prediction. --- 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 940a6af83..960491830 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,5 +1,5 @@ // Predict and explain first... - +// it returns undefined as it can't find 0 because this is an object its iterating with and not an array // This code should log out the houseNumber from the address object // but it isn't working... // Fix anything that isn't working From 4a888c99f00a6de812c1ce5c88526a5525fc8d87 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 11:01:20 +0000 Subject: [PATCH 02/30] fixed the error of [0] to ["houseNumber"], i think I can also use ${address.houseNumber} not sure which is best to use. --- 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 960491830..3514c69e5 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -12,4 +12,4 @@ const address = { postcode: "XYZ 123", }; -console.log(`My house number is ${address[0]}`); +console.log(`My house number is ${address["houseNumber"]}`); From 809ccc7d7fadd35da629f1b3319ab477a909e63d Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 11:13:49 +0000 Subject: [PATCH 03/30] done the prediction --- Sprint-2/debug/author.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 8c2125977..787a8da23 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,5 +1,6 @@ // Predict and explain first... - +// value is undefined, its not seen in the code at all. +// Ah error said it is not iterable, i didnt spot the for...of loop there, so its not seeing the value as an option in the object. // 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 b8b4cc07a56dce76a80665a191cd9f164e1765a8 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 11:14:37 +0000 Subject: [PATCH 04/30] fixed the for...loop --- Sprint-2/debug/author.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 787a8da23..59cef7b77 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -12,6 +12,6 @@ const author = { alive: true, }; -for (const value of author) { +for (const value of Object.values(author)) { console.log(value); } From fe145bf05133ab754e1dd09aae059d332efc96fa Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 11:20:20 +0000 Subject: [PATCH 05/30] done predictions --- Sprint-2/debug/recipe.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cd..e6c9fbbcb 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,5 +1,6 @@ // Predict and explain first... - +// it does not make a new line as just pressing enter wont work for that. +// I was wrong, ingredients is showing [object Object], as it wont log out a full object like this. // 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? From 39104370555675fa3a7503420d3736d9dc51a271 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 11:25:19 +0000 Subject: [PATCH 06/30] Fixed the code and using \n for the new lines. --- Sprint-2/debug/recipe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index e6c9fbbcb..fc82e33e4 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -13,4 +13,4 @@ const recipe = { console.log(`${recipe.title} serves ${recipe.serves} ingredients: -${recipe}`); +${recipe.ingredients.join("\n")}`); From 69ec2cbaa34b4b809edd4ca30e6d1360ee17b974 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 11:47:15 +0000 Subject: [PATCH 07/30] building code, start with thrown error. --- Sprint-2/implement/contains.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a..0748a8df2 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,8 @@ -function contains() {} +function contains(object, property) { + if (!Array.isArray(object)) { + toThrow new Error("contains requires an object") + } + +}; module.exports = contains; From a1b225a967b495ec797e5e57883de8a8894d9f2d Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 11:48:28 +0000 Subject: [PATCH 08/30] fixing errors --- Sprint-2/implement/contains.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 0748a8df2..c396495c2 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,8 +1,7 @@ function contains(object, property) { - if (!Array.isArray(object)) { - toThrow new Error("contains requires an object") - } - -}; + if (Array.isArray(object)) { + throw new Error("contains requires an object"); + } +} module.exports = contains; From 3ae2c2ab906a5bfb270efa419e3c6e3f2bfd6edb Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 11:53:56 +0000 Subject: [PATCH 09/30] built test for checking true for object contains property --- Sprint-2/implement/contains.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 719272787..435c01798 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -19,6 +19,10 @@ 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("When passed an object and a property name returns true", () => { + expect(contains({ a: 1, b: 2 }, "a")).toBe(true); + // Check the expected result +}); // Given an empty object // When passed to contains From 8231232a034b902249e4a6f031fe8ee01846710d Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 12:05:22 +0000 Subject: [PATCH 10/30] added in a true or false using "in" --- Sprint-2/implement/contains.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index c396495c2..1efb69e87 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -2,6 +2,7 @@ function contains(object, property) { if (Array.isArray(object)) { throw new Error("contains requires an object"); } + return property in object; } module.exports = contains; From cfaf2b534ecabe23cec00ff79314aae54eab801c Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 12:06:46 +0000 Subject: [PATCH 11/30] removed unneeded comments --- Sprint-2/implement/contains.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 435c01798..3e65bbbe8 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -21,7 +21,6 @@ as an array isn't an object // Then it should return true if the object contains the property, false otherwise test("When passed an object and a property name returns true", () => { expect(contains({ a: 1, b: 2 }, "a")).toBe(true); - // Check the expected result }); // Given an empty object From 5a1735e8fc08a1ecfcb0a15ec340f416c2bee354 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 12:10:48 +0000 Subject: [PATCH 12/30] added test for non-existent property name --- Sprint-2/implement/contains.test.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 3e65bbbe8..260f696ae 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -19,7 +19,7 @@ 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("When passed an object and a property name returns true", () => { +test("When passed an object and a property name, returns true", () => { expect(contains({ a: 1, b: 2 }, "a")).toBe(true); }); @@ -31,10 +31,16 @@ test.todo("contains on empty object returns false"); // Given an object with properties // When passed to contains with an existing property name // Then it should return true +test("Given an object with properties, returns true", () => { + expect(contains({ a: 1, b: 2 }, "a")).toBe(true); +}); // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false +test("Given an object with a non-existent property name, returns false", () => { + expect(contains({ a: 1, b: 2 }, "c")).toBe(false); +}); // Given a value that isn't an object - an array, a string, a number, // null, or no argument at all From f411077db5656522cd95b5ab940d8364c8c661b8 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 12:14:31 +0000 Subject: [PATCH 13/30] test for empty object --- Sprint-2/implement/contains.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 260f696ae..1aef7c6e6 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -26,7 +26,9 @@ test("When passed an object and a property name, returns true", () => { // Given an empty object // When passed to contains // Then it should return false -test.todo("contains on empty object returns false"); +test("Given an empty object, returns false", () => { + expect(contains({}, "a")).toBe(false); +}); // Given an object with properties // When passed to contains with an existing property name From e0082d84f095ebb974de3028b171a1cf2a1936a2 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 12:21:51 +0000 Subject: [PATCH 14/30] added in final test for throwing error for not containing object --- Sprint-2/implement/contains.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 1aef7c6e6..2dfa7b9fa 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -49,3 +49,6 @@ test("Given an object with a non-existent property name, returns false", () => { // When passed to contains // Then it should throw Error("contains requires an object") // (careful: typeof [] and typeof null are both "object") +test("Given an array, throws an error 'contains requires an object'", () => { + expect(() => contains([])).toThrow("contains requires an object"); +}); From e07a5358a746da788a8472fac7b932c7cc432fce Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 16:33:25 +0000 Subject: [PATCH 15/30] Added in test required and fixed errors in code --- Sprint-2/implement/lookup.js | 5 +++-- Sprint-2/implement/lookup.test.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index a6746e07f..3f57a59f1 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,5 +1,6 @@ -function createLookup() { - // implementation here +function createLookup(countryCurrencyPairs) { + const lookup = Object.fromEntries(countryCurrencyPairs); + return lookup; } module.exports = createLookup; diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 547e06c5a..7c597b17e 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -1,6 +1,6 @@ const createLookup = require("./lookup.js"); -test.todo("creates a country currency code lookup for multiple codes"); +// test.todo("creates a country currency code lookup for multiple codes"); /* @@ -33,3 +33,14 @@ It should return: 'CA': 'CAD' } */ +test("Given an array of arrays representing country code and currency code pairs should return in object", () => { + expect( + createLookup([ + ["US", "USD"], + ["CA", "CAD"], + ]) + ).toEqual({ + US: "USD", + CA: "CAD", + }); +}); From 781d48ea44b565c2867aa2dd39d347d16164177d Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 16:57:40 +0000 Subject: [PATCH 16/30] done code for tally, need to look into it more. --- Sprint-2/implement/tally.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index f47321812..bfefc5503 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,3 +1,14 @@ -function tally() {} +function tally(array) { + const lookup = {}; + + for (const item of array) { + if (lookup[item]) { + lookup[item] += 1; + } else { + lookup[item] = 1; + } + } + return lookup; +} module.exports = tally; From 47dcb5d42d0f1496f9292857a37f1e03c3e092d2 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 17:02:42 +0000 Subject: [PATCH 17/30] started with testing, done the first on with just one a --- 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 ca763c296..710647447 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -19,6 +19,9 @@ 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("When passed an array of items should return object containing count for each", () => { + expect(tally(["a"])).toEqual({ a: 1 }); +}); // Given an empty array // When passed to tally From 0cd4ffe78cda2c54375a811f0e1806ed92597974 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 17:03:38 +0000 Subject: [PATCH 18/30] tested empty array --- 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 710647447..983359a01 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -27,6 +27,9 @@ test("When passed an array of items should return object containing count for ea // When passed to tally // Then it should return an empty object test.todo("tally on an empty array returns an empty object"); +test("When passed an empty array should return empty object", () => { + expect(tally([])).toEqual({}); +}); // Given an array with duplicate items // When passed to tally From 7747e05ccf525b771bfb3eec41ec55c11df1c390 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 17:04:38 +0000 Subject: [PATCH 19/30] test for duplicate items. --- 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 983359a01..aea5833cb 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -34,6 +34,9 @@ test("When passed an empty array should return empty object", () => { // Given an array with duplicate items // When passed to tally // Then it should return counts for each unique item +test("When passed an array of duplicate items should return object containing correct count", () => { + expect(tally(["a", "a", "a"])).toEqual({ a: 3 }); +}); // Given an invalid input like a string, a number, or no argument at all // When passed to tally From fdd63d073a8e3ac10403be702270bb69e09cd3b7 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Wed, 11 Nov 2026 17:09:13 +0000 Subject: [PATCH 20/30] added in code and test for thrown error. --- Sprint-2/implement/tally.js | 3 +++ Sprint-2/implement/tally.test.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index bfefc5503..534f382d7 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,5 +1,8 @@ function tally(array) { const lookup = {}; + if (!Array.isArray(array)) { + throw new Error("tally requires an array"); + } for (const item of array) { if (lookup[item]) { diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index aea5833cb..c4f7291af 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -41,3 +41,6 @@ test("When passed an array of duplicate items should return object containing co // 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("WGiven an invalid input should throw error 'tally requires an array'", () => { + expect(() => tally("im a string")).toThrow("tally requires an array"); +}); From ea97ab945a6e5f5769b36df244b4e82d360c333c Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 12 Nov 2026 11:53:58 +0000 Subject: [PATCH 21/30] fixed the code to run the first test . --- 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 45ec4e5f3..efc087298 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 = pair.split("=")[0]; + const value = pair.split("=").slice(1).join("="); queryParams[key] = value; } From 72da3ae6fc9f9b48770ab6cb9476f58a93ee69c6 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 12 Nov 2026 12:13:46 +0000 Subject: [PATCH 22/30] added in code for 2nd test and cleaned up some code. --- Sprint-2/implement/querystring.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index efc087298..2ce1cdfa0 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -6,8 +6,13 @@ function parseQueryString(queryString) { const keyValuePairs = queryString.split("&"); for (const pair of keyValuePairs) { - const key = pair.split("=")[0]; - const value = pair.split("=").slice(1).join("="); + if (pair === "") { + continue; + } + const parts = pair.split("="); + + const key = parts[0]; + const value = parts.slice(1).join("="); queryParams[key] = value; } From fc2ec5940bdbaffc2ebe17bac3a250e3adc3f2b0 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 12 Nov 2026 12:23:50 +0000 Subject: [PATCH 23/30] edited code to have decodeURIComponent --- Sprint-2/implement/querystring.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 2ce1cdfa0..94bb6190b 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -11,8 +11,8 @@ function parseQueryString(queryString) { } const parts = pair.split("="); - const key = parts[0]; - const value = parts.slice(1).join("="); + const key = decodeURIComponent(parts[0]); + const value = decodeURIComponent(parts.slice(1).join("=")); queryParams[key] = value; } From ec001df410eaa595b16dbf72e33b4c89b5fe4acf Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 12 Nov 2026 12:47:31 +0000 Subject: [PATCH 24/30] all tests are working --- Sprint-2/implement/querystring.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 328b8df61..e9e0e9abd 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 192ed3535c2589ca5e147d7cdfda8178fbbe3b64 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 12 Nov 2026 15:42:34 +0000 Subject: [PATCH 25/30] answered questions now working on code and tests for the tasks. --- Sprint-2/interpret/invert.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index bb353fb1f..d8b128323 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -12,18 +12,27 @@ function invert(obj) { for (const [key, value] of Object.entries(obj)) { invertedObj.key = value; } - return invertedObj; } +module.exports = invert; // a) What is the current return value when invert is called with { a : 1 } +// console.log(invert({ a: 1 })); +// It is: { key: 1 } // b) What is the current return value when invert is called with { a: 1, b: 2 } +// console.log(invert({ a: 1, b: 2 })); +// it is: { key: 2 } // c) What is the target return value when invert is called with {a : 1, b: 2} +// it should be : { 1: "a", 2: "b" } // c) What does Object.entries return? Why is it needed in this program? +// it is containing each key/value pair +// it takes an object and turns it into an array // d) Explain why the current return value is different from the target output +// its because of "invertedObj.key = value;" each time it is running its writes +// to the same property of "key" basically overwriting the previous one. // e) Fix the implementation of invert (and write tests to prove it's fixed!) From 346794658842f46169fa5d958644ac7ce1778b7b Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 12 Nov 2026 15:52:19 +0000 Subject: [PATCH 26/30] fixed code and added in first test for correct invert --- Sprint-2/interpret/invert.js | 2 +- Sprint-2/interpret/invert.test.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Sprint-2/interpret/invert.test.js diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index d8b128323..64b2e7dbd 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; } diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js new file mode 100644 index 000000000..828e0f19a --- /dev/null +++ b/Sprint-2/interpret/invert.test.js @@ -0,0 +1,5 @@ +const invert = require("./invert.js"); + +test("Inverting original input correctly", () => { + expect(invert({ a: 1 })).toEqual({ 1: "a" }); +}); From 8ee667ed9f4d59ebd218a5d5374ec56577d82b83 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 12 Nov 2026 15:56:17 +0000 Subject: [PATCH 27/30] added test for 2 objects and 2 properties --- Sprint-2/interpret/invert.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 828e0f19a..5451164ca 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -1,5 +1,11 @@ const invert = require("./invert.js"); +// inverting original input test("Inverting original input correctly", () => { expect(invert({ a: 1 })).toEqual({ 1: "a" }); }); + +// inverting original input of 2 objects and 2 properties +test("Inverting original input correctly", () => { + expect(invert({ a: 1, b: 2 })).toEqual({ 1: "a", 2: "b" }); +}); From 0066a76ff822fbbb2efbd1dcd829b2a8965ac128 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 12 Nov 2026 16:01:13 +0000 Subject: [PATCH 28/30] test for empty object --- Sprint-2/interpret/invert.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 5451164ca..20b3e912c 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -9,3 +9,8 @@ test("Inverting original input correctly", () => { test("Inverting original input correctly", () => { expect(invert({ a: 1, b: 2 })).toEqual({ 1: "a", 2: "b" }); }); + +// inverting an empty object +test("Inverting original input correctly", () => { + expect(invert({})).toEqual({}); +}); From 9a3ac64db5a79f749193b5bd59a14a0ab0a29b06 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 12 Nov 2026 16:14:31 +0000 Subject: [PATCH 29/30] added tests for empty strings and objects --- Sprint-2/interpret/invert.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 20b3e912c..1120c981d 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -14,3 +14,13 @@ test("Inverting original input correctly", () => { test("Inverting original input correctly", () => { expect(invert({})).toEqual({}); }); + +// inverting an object with an empty string as a key +test("Inverting original input correctly", () => { + expect(invert({ a: "" })).toEqual({ "": "a" }); +}); + +// inverting an empty object with an string as a key +test("Inverting original input correctly", () => { + expect(invert({ "": 1 })).toEqual({ 1: "" }); +}); From 80a82ec5875a71574bf60ab91bf015a5ee61cbeb Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 12 Nov 2026 16:21:37 +0000 Subject: [PATCH 30/30] fixed typing errors and make sure test discriptions are correct to tests --- Sprint-2/interpret/invert.test.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 1120c981d..8b8eaaf4c 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -1,12 +1,12 @@ const invert = require("./invert.js"); // inverting original input -test("Inverting original input correctly", () => { +test("Inverting original input of 1 property", () => { expect(invert({ a: 1 })).toEqual({ 1: "a" }); }); // inverting original input of 2 objects and 2 properties -test("Inverting original input correctly", () => { +test("Inverting original input of 2 properties", () => { expect(invert({ a: 1, b: 2 })).toEqual({ 1: "a", 2: "b" }); }); @@ -15,12 +15,17 @@ test("Inverting original input correctly", () => { expect(invert({})).toEqual({}); }); -// inverting an object with an empty string as a key -test("Inverting original input correctly", () => { +// Inverting an object with an empty string as a value +test("Inverting an object with an empty string as a value", () => { expect(invert({ a: "" })).toEqual({ "": "a" }); }); -// inverting an empty object with an string as a key -test("Inverting original input correctly", () => { +// Inverting an object with an empty string as a key +test("Inverting an object with an empty string as a key", () => { expect(invert({ "": 1 })).toEqual({ 1: "" }); }); + +// Inverting an object with multiple properties sharing the same value +test("Inverting an object with multiple properties sharing the same value", () => { + expect(invert({ a: 2, b: 2, c: 2 })).toEqual({ 2: "a", 2: "b", 2: "c" }); +});