From 71fa218a8f7b7e014738432dadc1497470ae9ed9 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 24 Oct 2025 10:12:47 +0100 Subject: [PATCH 01/21] Add initial test file for mean calculations --- prep/mean.test.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 prep/mean.test.js diff --git a/prep/mean.test.js b/prep/mean.test.js new file mode 100644 index 000000000..e69de29bb From 927769b17de592f6887d046ba0bce8604ffcbd09 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 24 Oct 2025 10:13:42 +0100 Subject: [PATCH 02/21] Add mean.js file for mean calculations --- prep/mean.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 prep/mean.js diff --git a/prep/mean.js b/prep/mean.js new file mode 100644 index 000000000..e69de29bb From a393af9cf00e0164a447b9e3a607bb1b6e6b8dc1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 10:05:36 +0000 Subject: [PATCH 03/21] Remove mean.js and mean.test.js files --- prep/mean.js | 0 prep/mean.test.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 prep/mean.js delete mode 100644 prep/mean.test.js diff --git a/prep/mean.js b/prep/mean.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/prep/mean.test.js b/prep/mean.test.js deleted file mode 100644 index e69de29bb..000000000 From 256a0bb599f8494bc6e2bef96544d1f87f151812 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 17:32:17 +0000 Subject: [PATCH 04/21] Fix address object access to correctly log house number --- Sprint-2/debug/address.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 940a6af83..1193eacca 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,5 +1,5 @@ // Predict and explain first... - +//will log undefined , there is no "0" key, objects do not have indexes so we can't use [0] // This code should log out the houseNumber from the address object // but it isn't working... // Fix anything that isn't working @@ -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}`);//or ["houseNumber"] From 93dca5ed88c39c663fb129e88c815dcd567d8e13 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 18:02:07 +0000 Subject: [PATCH 05/21] Fix loop iteration to correctly log author object properties --- Sprint-2/debug/author.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 8c2125977..592a83087 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,5 +1,5 @@ // Predict and explain first... - +// it comes out of the loop after the first console.log // 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 +11,6 @@ const author = { alive: true, }; -for (const value of author) { - console.log(value); +for (const value in author) { + console.log(`${value}:${author[value]}`); } From 538d536141e6bfdd76a0588bcd14f2def0ec3d54 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 18:25:37 +0000 Subject: [PATCH 06/21] Fix recipe logging to display ingredients on separate lines --- Sprint-2/debug/recipe.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cd..7458b277f 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,5 +1,5 @@ // Predict and explain first... - +//it will log everything in one line, we need to add \n // This program should log out the title, how many it serves and the ingredients. // Each ingredient should be logged on a new line // How can you fix it? @@ -10,6 +10,8 @@ const recipe = { ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title} serves ${recipe.serves} - ingredients: -${recipe}`); +console.log(`${recipe.title}\nserves ${recipe.serves}\ningredients:`); + +for (const ingredient of recipe.ingredients) { + console.log(ingredient); +} From 608a2f2fe4c5d465559cdbfd1481d0de3f013c9b Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 18:26:47 +0000 Subject: [PATCH 07/21] Fix recipe logging format to display title, serves, and ingredients in a single line --- 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 7458b277f..42dd9f549 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -10,7 +10,7 @@ const recipe = { ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title}\nserves ${recipe.serves}\ningredients:`); +console.log(`${recipe.title}, serves ${recipe.serves}, ingredients:`); for (const ingredient of recipe.ingredients) { console.log(ingredient); From 3a82eedd9e8cc0b7d6f9b4c7989e6c6a475e003d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 20:05:06 +0000 Subject: [PATCH 08/21] Add test case for contains function with empty object --- Sprint-2/implement/contains.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 326bdb1f2..f7d8ea2c8 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -16,11 +16,16 @@ as the object doesn't contains a key of 'c' // Given a contains function // When passed an object and a property name // Then it should return true if the object contains the property, false otherwise +test("if the object contains the property, return 'true'",()=>{ + expect(contains({a:1},"a")).toEqual(true) +}) // Given an empty object // When passed to contains // Then it should return false -test.todo("contains on empty object returns false"); +test("contains an empty object returns false",()=>{ + expect(contains({},"a")).toEqual(false) +}); // Given an object with properties // When passed to contains with an existing property name From dbd5551a5ea87329473d15cca1dd6ced6dbf7f5b Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 20:05:17 +0000 Subject: [PATCH 09/21] Implement contains function to check for property existence in an object --- Sprint-2/implement/contains.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a..124c7e729 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,13 @@ -function contains() {} +function contains(obj,property) { +if(Object.keys(obj).length===0){ + return false +} +if(property in obj){ + return true +} + +} module.exports = contains; + + From 1769faf762f6e94160f56a33a6ba01bffb1aa28e Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 20:29:49 +0000 Subject: [PATCH 10/21] Add additional test cases for contains function to cover non-existent properties and invalid parameters --- Sprint-2/implement/contains.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index f7d8ea2c8..df3eaa15a 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -19,6 +19,9 @@ as the object doesn't contains a key of 'c' test("if the object contains the property, return 'true'",()=>{ expect(contains({a:1},"a")).toEqual(true) }) +test("if the object doesn't contain the property return 'false'",()=>{ + expect(contains({a:1,d:7},"m")).toEqual(false) +}) // Given an empty object // When passed to contains @@ -31,6 +34,7 @@ test("contains an empty object returns false",()=>{ // When passed to contains with an existing property name // Then it should return true + //<<> // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false @@ -38,3 +42,6 @@ test("contains an empty object returns false",()=>{ // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error +test("when instead of an object literal the parameter is an array throw error",()=>{ + expect(()=>contains([],"a")).toThrow("Parameter is not an object literal") +}) From 8fd279f2d83df94a3e6a72745c06b1919035a2a1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 20:30:01 +0000 Subject: [PATCH 11/21] Add error handling for non-object parameters in contains function --- 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 124c7e729..3d722212c 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,4 +1,7 @@ function contains(obj,property) { + if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { + throw new Error("Parameter is not an object literal"); + } if(Object.keys(obj).length===0){ return false } @@ -6,6 +9,7 @@ if(property in obj){ return true } +return false } module.exports = contains; From 1ff152e6a042f8b75fed8e71570efac4c8f98f38 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 20:46:37 +0000 Subject: [PATCH 12/21] Refactor test cases for contains function for improved readability and consistency --- Sprint-2/implement/contains.test.js | 31 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index df3eaa15a..6565d518e 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -16,25 +16,32 @@ 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("if the object contains the property, return 'true'",()=>{ - expect(contains({a:1},"a")).toEqual(true) -}) -test("if the object doesn't contain the property return 'false'",()=>{ - expect(contains({a:1,d:7},"m")).toEqual(false) -}) +test("if the object contains the property, return 'true'", () => { + expect(contains({ a: 1 }, "a")).toEqual(true); +}); +test("if the object contains the property, return 'true'", () => { + expect(contains({ a: 1, "a,s,3": "op" }, ["a", "s", 3])).toEqual(true); +}); + +test("if the object doesn't contain the property return 'false'", () => { + expect(contains({ a: 1, d: 7 }, "m")).toEqual(false); +}); +test("if the object doesn't contain the property return 'false'", () => { + expect(contains({ a: 1, s: 7 }, [1, 2, "a"])).toEqual(false); +}); // Given an empty object // When passed to contains // Then it should return false -test("contains an empty object returns false",()=>{ - expect(contains({},"a")).toEqual(false) +test("contains an empty object returns false", () => { + expect(contains({}, "a")).toEqual(false); }); // Given an object with properties // When passed to contains with an existing property name // Then it should return true - //<<> +//<<> // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false @@ -42,6 +49,6 @@ test("contains an empty object returns false",()=>{ // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error -test("when instead of an object literal the parameter is an array throw error",()=>{ - expect(()=>contains([],"a")).toThrow("Parameter is not an object literal") -}) +test("when instead of an object literal the parameter is an array throw error", () => { + expect(() => contains([], "a")).toThrow("Parameter is not an object literal"); +}); From 2982bf246f9d01ba55edefec464bcb42feeac451 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 20:46:47 +0000 Subject: [PATCH 13/21] Fix formatting inconsistencies in contains function for improved readability --- Sprint-2/implement/contains.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 3d722212c..ce68fb81d 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,17 +1,16 @@ -function contains(obj,property) { - if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { - throw new Error("Parameter is not an object literal"); - } -if(Object.keys(obj).length===0){ - return false -} -if(property in obj){ - return true -} +function contains(obj, property) { + if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { + throw new Error("Parameter is not an object literal"); + } + if (Object.keys(obj).length === 0) { + return false; + } + + if (property in obj) { + return true; + } -return false + return false; } module.exports = contains; - - From cb3b23c0c877b21ec14d4b67858373c7459039ad Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 21:18:55 +0000 Subject: [PATCH 14/21] Implement test for createLookup function to validate country-currency code mapping --- Sprint-2/implement/lookup.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 547e06c5a..d401513f3 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -1,6 +1,14 @@ 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", () => { + expect( + createLookup([ + ["US", "USD"], + ["CA", "CAD"], + ["RO", "RON"], + ]) + ).toEqual({ US: "USD", CA: "CAD", RO: "RON" }); +}); /* From e56a2bf13c4b2a94e336bf5416ffbaceb65a6f4d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 2 Nov 2025 21:19:06 +0000 Subject: [PATCH 15/21] Implement createLookup function to map country to currency --- Sprint-2/implement/lookup.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index a6746e07f..fd3a85055 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,5 +1,18 @@ -function createLookup() { - // implementation here +function createLookup(countryCurrency) { + let countryCurrencyPairs = {}; + for (const pair of countryCurrency) { + let country = pair[0]; + let currency = pair[1]; + countryCurrencyPairs[country] = currency; + } + return countryCurrencyPairs; } +console.log( + createLookup([ + ["US", "USD"], + ["CA", "CAD"], + ["RO", "RON"], + ]) +); module.exports = createLookup; From 3f4a1154f3477cce1e7779dd0665550a81b29239 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 3 Nov 2025 09:29:08 +0000 Subject: [PATCH 16/21] Add tests for tally function to validate behavior with empty and invalid inputs --- Sprint-2/implement/tally.test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 2ceffa8dd..a68e13ec4 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -19,16 +19,27 @@ 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("on an array of items returns an object containing the count for each unique item ", () => { + expect(tally(["a", "a", "a", "h"])).toEqual({ a: 3, h: 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 duplicate items // When passed to tally // Then it should return counts for each unique item +test("on an array of items returns an object containing the count for each unique item ", () => { + expect(tally([1,1,4,4,4,4])).toEqual({ 1: 2, 4: 4 }); +}); // Given an invalid input like a string // When passed to tally // Then it should throw an error +test("given invalid input , throw error",()=>{ + expect(() => tally("hello")).toThrow("Invalid input"); +}) From 493e3f11da121629a52da4a23bf58b568d4cf1bd Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 3 Nov 2025 09:29:26 +0000 Subject: [PATCH 17/21] Implement tally function to count occurrences of elements in an array with input validation --- Sprint-2/implement/tally.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index f47321812..6ed7f6ec5 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,3 +1,17 @@ -function tally() {} +function tally(arr) { +const objectCount={} +if(!Array.isArray(arr)){ + throw new Error("Invalid input"); +} +if(arr.length===0){ + return {} +} +for(const element of arr){ + objectCount[element]=objectCount[element] ? objectCount[element] +1:1; +} +return objectCount + +} + module.exports = tally; From 577ae89da10e70497453eb7c657f4f073b633ebe Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 3 Nov 2025 12:45:07 +0000 Subject: [PATCH 18/21] Refactor query string tests for improved clarity and structure --- Sprint-2/implement/querystring.test.js | 48 ++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 3e218b789..20eac2231 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -3,10 +3,52 @@ // 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", + expect(parseQueryString("equation=x=y+1")).toEqual({ equation: "x=y+1" }); +}); + +test("parse querystring with multiple values", () => { + expect(parseQueryString("equation=x=y+1&sound=none")).toEqual({ + equation: "x=y+1", + sound: "none", }); }); + +test("parse querystring with multiple ==", () => { + expect(parseQueryString("equation==x=y+1&sound=none")).toEqual({ + equation: "=x=y+1", + sound: "none", + }); +}); + +test("parse querystring with multiple &&", () => { + expect(parseQueryString("equation=x=y+1&&sound=none")).toEqual({ + equation: "x=y+1", + sound: "none", + }); +}); + +test("parse querystring with no =", () => { + expect(parseQueryString("equation=x=y+1&soundnone")).toEqual({ + equation: "x=y+1", + soundnone:"", + }); +}); + +//don't know how to do this +// test("parse querystring with multiple ==", () => { +// expect(parseQueryString("equation==x=y+1&sound=none")).toEqual({ +// equation=: "x=y+1", +// sound: "none", +// }); +// }); + +//don't know how to do this +// test("parses querystring values containing &", () => { +// expect(parseQueryString("&equation=x=y+1&sound=none")).toEqual({ +// "&equation": "x=y+1", +// sound: "none", +// }); +// }); From 99caad7e0c21beec37402d312d55956b8824eed2 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 3 Nov 2025 12:45:19 +0000 Subject: [PATCH 19/21] Refactor parseQueryString function for improved handling of empty pairs and key-value parsing --- Sprint-2/implement/querystring.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 45ec4e5f3..0a93c3551 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -3,14 +3,30 @@ function parseQueryString(queryString) { if (queryString.length === 0) { return queryParams; } + const keyValuePairs = queryString.split("&"); for (const pair of keyValuePairs) { - const [key, value] = pair.split("="); - queryParams[key] = value; + if(pair===""){ + continue + } + const equalIndex=pair.indexOf("=") + if (equalIndex === -1) { + queryParams[pair]=""; + continue + } + const key=pair.substring(0,equalIndex) + const value=pair.substring(equalIndex+1) + queryParams[key]=value + } return queryParams; } +//console.log(parseQueryString("equationxy+1")); module.exports = parseQueryString; + + + + From f998538f4c1140d66f4772126ea0f0e1ef149c31 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 3 Nov 2025 14:10:40 +0000 Subject: [PATCH 20/21] Fix invert function to correctly swap keys and values in the object --- Sprint-2/interpret/invert.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index bb353fb1f..59705c738 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -10,20 +10,26 @@ function invert(obj) { const invertedObj = {}; for (const [key, value] of Object.entries(obj)) { - invertedObj.key = value; + invertedObj[value] = key; } return invertedObj; } // a) What is the current return value when invert is called with { a : 1 } +//["a",1] // b) What is the current return value when invert is called with { a: 1, b: 2 } +//[[ "a", 1], ["b", 2]] // c) What is the target return value when invert is called with {a : 1, b: 2} +//{"1":a,"2":b} // c) What does Object.entries return? Why is it needed in this program? +//returns an array so we can access each element of it so we can swap their order // d) Explain why the current return value is different from the target output +//it creates a new key:value pair with the key being "key",also it doesnt invert the key with the value // e) Fix the implementation of invert (and write tests to prove it's fixed!) +module.exports = invert; From e098bba2de58ee24fa8d64a365e0e3fb959a345a Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 3 Nov 2025 14:10:52 +0000 Subject: [PATCH 21/21] Add test for invert function to verify key-value swapping behavior --- Sprint-2/interpret/invert.test.js | 4 ++++ 1 file changed, 4 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..c0e0db0b6 --- /dev/null +++ b/Sprint-2/interpret/invert.test.js @@ -0,0 +1,4 @@ +const invert = require("./invert.js"); +test("swap the keys and values in the object", () => { + expect(invert({ a: 1, asd: "d3e" })).toEqual({ 1: "a", d3e: "asd" }); +});