From 5afdf823b3620b0b54655feb2299b3a9583a9af2 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 12:16:51 +0000 Subject: [PATCH 01/32] correct access to houseNumber in address object --- Sprint-2/debug/address.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 940a6af83..1b79994c6 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,4 +1,6 @@ // Predict and explain first... +// it will print : My house number is undefined +//objects aren't indexed // This code should log out the houseNumber from the address object // but it isn't working... @@ -12,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 8a0b3af6d285bdc99ca069146ca9eadde72d4bde Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 12:27:14 +0000 Subject: [PATCH 02/32] correct iteration method to log author properties --- Sprint-2/debug/author.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 8c2125977..27c25c3a6 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -1,4 +1,6 @@ // Predict and explain first... +//for...of works only on iterable data types +// we will get an error // 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 +13,6 @@ const author = { alive: true, }; -for (const value of author) { - console.log(value); +for (const key in author) { + console.log(author[key]); } From f8203998d50689d5027e63d70be81e5a8bb8ce5a Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 12:41:14 +0000 Subject: [PATCH 03/32] update recipe logging to display ingredients on new lines --- Sprint-2/debug/recipe.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cd..b0244844f 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,4 +1,8 @@ // Predict and explain first... +//this will log: bruschetta serves 2 ingredients: title: "bruschetta", + // serves: 2, + // ingredients: ["olive oil", "tomatoes", "salt", "pepper"], +//instead of the ingredients it prints the whole object again , also there is no \n // 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 +14,10 @@ const recipe = { ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title} serves ${recipe.serves} - ingredients: -${recipe}`); +let ingredients=[] + for(let ingredient of recipe.ingredients){ + ingredients.push(ingredient) + } + console.log( + `${recipe.title} serves ${recipe.serves} ingredients:\n${ingredients.join("\n")}`) + From 6e37fe5c4445dc075dc8911e0e408fa7b742a08a Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 14:39:12 +0000 Subject: [PATCH 04/32] implement contains function and add tests for empty and existing properties --- Sprint-2/implement/contains.js | 13 ++++++++++++- Sprint-2/implement/contains.test.js | 10 +++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a..2afb09458 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,14 @@ -function contains() {} +function contains(obj,propertyName) { + + +if(Object.keys(obj).length!==0){ + return true +} +if (Object.keys(obj) === propertyName) { + return true; +} +return false +} +console.log(contains({a:"t",k:5},"k")); module.exports = contains; diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 326bdb1f2..f6a687e40 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -20,11 +20,19 @@ as the object doesn't contains a key of 'c' // 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 and propertyName='k' returns false", () => { + expect(contains({}, "k")).toEqual(false); +}); // Given an object with properties // When passed to contains with an existing property name // Then it should return true +test( + "when contains is called with an object and an existing property name as arguments,it returns true ",()=>{ + expect(contains({a:9},"a")).toEqual(true) + } +); + // Given an object with properties // When passed to contains with a non-existent property name From 4fd1b2de973ced4481678b64454879925e83bbc5 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 14:40:57 +0000 Subject: [PATCH 05/32] fix contains function to correctly check for property existence in object --- Sprint-2/implement/contains.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 2afb09458..51b50e700 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -4,7 +4,7 @@ function contains(obj,propertyName) { if(Object.keys(obj).length!==0){ return true } -if (Object.keys(obj) === propertyName) { +if (Object.keys(obj).includes(propertyName)) { return true; } return false From 400346f7b3dc3d0d305bfb417adc61a3aa3ba8c8 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 14:43:28 +0000 Subject: [PATCH 06/32] fix contains function to correctly return false for empty objects --- Sprint-2/implement/contains.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 51b50e700..bb215941d 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,14 +1,14 @@ function contains(obj,propertyName) { -if(Object.keys(obj).length!==0){ - return true +if(Object.keys(obj).length===0){ + return false } if (Object.keys(obj).includes(propertyName)) { return true; } return false } -console.log(contains({a:"t",k:5},"k")); +console.log(contains({a:"t",k:5},"o")); module.exports = contains; From 6e91927bf496c38d87c678a2c4c9b25fdf4ab872 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 14:45:57 +0000 Subject: [PATCH 07/32] add test case for contains function with non-existing property name --- 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 f6a687e40..59943cc1a 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -37,6 +37,10 @@ test( // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false +test("when contains is called with an object and a non-existing property name as arguments,it returns false ", () => { + expect(contains({ a: 9,color:"pink",day:"Sunday" }, "John")).toEqual(false); +}); + // Given invalid parameters like an array // When passed to contains From 06b37671ca689ba4dd5900921cbbc97cbdf8f305 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 14:58:28 +0000 Subject: [PATCH 08/32] add error handling test for contains function with invalid object type --- Sprint-2/implement/contains.js | 23 ++++++++++++----------- Sprint-2/implement/contains.test.js | 4 ++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index bb215941d..36eacc776 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,14 +1,15 @@ -function contains(obj,propertyName) { - - -if(Object.keys(obj).length===0){ - return false +function contains(obj, propertyName) { + if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { + throw new Error("Invalid object"); + } + if (Object.keys(obj).length === 0) { + return false; + } + if (Object.keys(obj).includes(propertyName)) { + return true; + } + return false; } -if (Object.keys(obj).includes(propertyName)) { - return true; -} -return false -} -console.log(contains({a:"t",k:5},"o")); +//console.log(contains({w:0}, [w])); module.exports = contains; diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 59943cc1a..ce132b050 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -45,3 +45,7 @@ test("when contains is called with an object and a non-existing property name as // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error +test("when contains is called with the string 'parameter' and propertyName='a' as arguments it throws an error", () => { + expect(() => contains("parameter", "a")).toThrow("Invalid object"); +}); + From bbb05bc56bba4634a7bf9ac6835f4d2a58fd72ae Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 15:00:36 +0000 Subject: [PATCH 09/32] remove commented-out console.log statement from contains function --- Sprint-2/implement/contains.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 36eacc776..f5ee45f31 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -10,6 +10,6 @@ function contains(obj, propertyName) { } return false; } -//console.log(contains({w:0}, [w])); + module.exports = contains; From 8f746c10c600da68cea0ac8cbaa46fcbe83878b0 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 15:17:48 +0000 Subject: [PATCH 10/32] implement test for createLookup function to validate country-currency code mapping --- Sprint-2/implement/lookup.test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/lookup.test.js b/Sprint-2/implement/lookup.test.js index 547e06c5a..9c37d1d6c 100644 --- a/Sprint-2/implement/lookup.test.js +++ b/Sprint-2/implement/lookup.test.js @@ -1,6 +1,16 @@ 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,when createLookup is passed[['US', 'USD'], ['CA', 'CAD']] it returns {'US': 'USD','CA': 'CAD'}", () => { + expect( + createLookup([ + ["US", "USD"], + ["CA", "CAD"], + ]) + ).toEqual({ + US: "USD", + CA: "CAD", + }); +}); /* From 202e093b8d0eed2cd077e36397451002c22f496a Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 15:29:43 +0000 Subject: [PATCH 11/32] implement createLookup function to map country codes to currency codes --- Sprint-2/implement/lookup.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/lookup.js b/Sprint-2/implement/lookup.js index a6746e07f..ad2e95bda 100644 --- a/Sprint-2/implement/lookup.js +++ b/Sprint-2/implement/lookup.js @@ -1,5 +1,19 @@ -function createLookup() { - // implementation here +function createLookup(array) { + let object={} + for(let element of array){ + let key=element[0] + let value=element[1] + object[key]=value + } + return object } +console.log( + createLookup([ + ["US", "USD"], + ["CA", "CAD"], + ]) +); + + module.exports = createLookup; From 1a3329e3fc6d53196795c1f4b38ec74acc327740 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 16:16:53 +0000 Subject: [PATCH 12/32] refactor parseQueryString function to improve key-value extraction logic --- 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 45ec4e5f3..e2c9f0d5d 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -6,11 +6,16 @@ function parseQueryString(queryString) { const keyValuePairs = queryString.split("&"); for (const pair of keyValuePairs) { - const [key, value] = pair.split("="); - queryParams[key] = value; + const indexOfEqual = pair.indexOf("="); + const key = [pair.slice(0,indexOfEqual)]; + const value = pair.slice(indexOfEqual+1); + queryParams[key]=value + } return queryParams; } +console.log(parseQueryString("equation=x=y+1")); + module.exports = parseQueryString; From 3796ceab6e421038c2809ece2bdc8c51e18c483c Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 16:41:55 +0000 Subject: [PATCH 13/32] fix: handle edge cases in parseQueryString function and update tests --- Sprint-2/implement/querystring.js | 9 +++++++-- Sprint-2/implement/querystring.test.js | 12 +++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index e2c9f0d5d..7c38b1802 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -4,18 +4,23 @@ function parseQueryString(queryString) { return queryParams; } const keyValuePairs = queryString.split("&"); + console.log(keyValuePairs); + for (const pair of keyValuePairs) { const indexOfEqual = pair.indexOf("="); + if(indexOfEqual===-1){ + queryParams[pair]="" + }else{ const key = [pair.slice(0,indexOfEqual)]; const value = pair.slice(indexOfEqual+1); queryParams[key]=value - + } } return queryParams; } -console.log(parseQueryString("equation=x=y+1")); +console.log(parseQueryString("equation")); module.exports = parseQueryString; diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 3e218b789..afa44712d 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -9,4 +9,14 @@ test("parses querystring values containing =", () => { expect(parseQueryString("equation=x=y+1")).toEqual({ "equation": "x=y+1", }); -}); +}); + +test("parses multiple querystring divided by &", () => { + expect(parseQueryString("equation=x=y+1&color=blue")).toEqual({ + equation: "x=y+1",color:"blue" + }); +}); + +test("it returns the value as an empty string if the querystring has no =",()=>{ + expect(parseQueryString("day")).toEqual({day:""}) +}) \ No newline at end of file From 0c37eb3881bd2a4e134479c8e1b3c0eff154c385 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 17:01:38 +0000 Subject: [PATCH 14/32] test: add case for empty key in querystring parsing --- Sprint-2/implement/querystring.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index afa44712d..6215cc3c0 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -19,4 +19,8 @@ test("parses multiple querystring divided by &", () => { test("it returns the value as an empty string if the querystring has no =",()=>{ expect(parseQueryString("day")).toEqual({day:""}) -}) \ No newline at end of file +}) + +test("it returns the key as an empty string if the querystring has no nothing before =", () => { + expect(parseQueryString("=day")).toEqual({"":"day" }); +}); \ No newline at end of file From 613c044246e8c17e3fa62708cbf01f7135db1e7b Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 26 Feb 2026 17:06:48 +0000 Subject: [PATCH 15/32] fix: clean up querystring parsing logic and improve test formatting --- Sprint-2/implement/querystring.js | 17 +++++++---------- Sprint-2/implement/querystring.test.js | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Sprint-2/implement/querystring.js b/Sprint-2/implement/querystring.js index 7c38b1802..8eec34cc0 100644 --- a/Sprint-2/implement/querystring.js +++ b/Sprint-2/implement/querystring.js @@ -4,23 +4,20 @@ function parseQueryString(queryString) { return queryParams; } const keyValuePairs = queryString.split("&"); - console.log(keyValuePairs); - for (const pair of keyValuePairs) { const indexOfEqual = pair.indexOf("="); - if(indexOfEqual===-1){ - queryParams[pair]="" - }else{ - const key = [pair.slice(0,indexOfEqual)]; - const value = pair.slice(indexOfEqual+1); - queryParams[key]=value + if (indexOfEqual === -1) { + queryParams[pair] = ""; + } else { + const key = [pair.slice(0, indexOfEqual)]; + const value = pair.slice(indexOfEqual + 1); + queryParams[key] = value; } } return queryParams; } -console.log(parseQueryString("equation")); - +console.log(parseQueryString("=equationtu")); module.exports = parseQueryString; diff --git a/Sprint-2/implement/querystring.test.js b/Sprint-2/implement/querystring.test.js index 6215cc3c0..c127aecce 100644 --- a/Sprint-2/implement/querystring.test.js +++ b/Sprint-2/implement/querystring.test.js @@ -3,24 +3,25 @@ // 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("parses multiple querystring divided by &", () => { expect(parseQueryString("equation=x=y+1&color=blue")).toEqual({ - equation: "x=y+1",color:"blue" + equation: "x=y+1", + color: "blue", }); -}); +}); -test("it returns the value as an empty string if the querystring has no =",()=>{ - expect(parseQueryString("day")).toEqual({day:""}) -}) +test("it returns the value as an empty string if the querystring has no =", () => { + expect(parseQueryString("day")).toEqual({ day: "" }); +}); test("it returns the key as an empty string if the querystring has no nothing before =", () => { - expect(parseQueryString("=day")).toEqual({"":"day" }); -}); \ No newline at end of file + expect(parseQueryString("=day")).toEqual({ "": "day" }); +}); From c279e017deb0b86ca3e282c67709798afa9b1c71 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 15:19:14 +0000 Subject: [PATCH 16/32] test: add tests for empty array and invalid input in tally function --- Sprint-2/implement/tally.test.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index 2ceffa8dd..e84084a17 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -1,7 +1,7 @@ const tally = require("./tally.js"); /** - * tally array + * tally array * * In this task, you'll need to implement a function called tally * that will take a list of items and count the frequency of each item @@ -23,12 +23,22 @@ const tally = require("./tally.js"); // Given an empty array // When passed to tally // Then it should return an empty object -test.todo("tally on an empty array returns an empty object"); +test("when an empty array is passed to tally it 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( + "when an array with duplicate items is passed to tally , it returns counts for each unique item",()=>{ + expect(tally(["t","d",5,"t",5])) + } +); // Given an invalid input like a string // When passed to tally // Then it should throw an error +test("when a string is passed to tally it throws error",()=>{ + expect(()=>tally("asd")).toThrow("Invalid input") +}) \ No newline at end of file From b93588f6fa47c6dbb105db017381f7d5a820ddaf Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 15:19:28 +0000 Subject: [PATCH 17/32] feat: implement tally function to count occurrences in an array --- Sprint-2/implement/tally.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index f47321812..b228d7243 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,3 +1,13 @@ -function tally() {} +function tally(array) { + + let obj = {}; + array.forEach((elem) => { + obj[elem] = (obj[elem] || 0) + 1; + }); + return obj; +} +console.log(tally("asd")); + + module.exports = tally; From 8acd98bb420cdf2e4bf669c4c82cfadb1e12dad9 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 15:29:05 +0000 Subject: [PATCH 18/32] test: fix assertion in tally function tests and ensure proper formatting --- Sprint-2/implement/tally.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index e84084a17..e7e4c2685 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -32,13 +32,13 @@ test("when an empty array is passed to tally it returns an empty object",()=>{ // Then it should return counts for each unique item test( "when an array with duplicate items is passed to tally , it returns counts for each unique item",()=>{ - expect(tally(["t","d",5,"t",5])) + expect(tally(["t", "d", 5, "t", 5])).toEqual({ t: 2, d: 1, 5: 2 }); } ); // Given an invalid input like a string // When passed to tally // Then it should throw an error -test("when a string is passed to tally it throws error",()=>{ - expect(()=>tally("asd")).toThrow("Invalid input") -}) \ No newline at end of file +test("when a string is passed to tally it throws error", () => { + expect(() => tally("asd")).toThrow("Invalid input"); +}); \ No newline at end of file From 327ba710d523b378065a107906f68ddd5d6d2a44 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 15:29:17 +0000 Subject: [PATCH 19/32] fix: add input validation to tally function to ensure array input --- Sprint-2/implement/tally.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index b228d7243..4dbdb47b0 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,12 +1,14 @@ function tally(array) { - + if(!Array.isArray(array)){ + throw new Error("Invalid input"); + } let obj = {}; array.forEach((elem) => { obj[elem] = (obj[elem] || 0) + 1; }); return obj; } -console.log(tally("asd")); +//console.log(tally("asd")); From 48a17dc50d87821dfa595aba6d4ddaf9cc5725bf Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 15:29:55 +0000 Subject: [PATCH 20/32] fix: improve formatting and consistency in tally function and tests --- Sprint-2/implement/tally.js | 7 ++----- Sprint-2/implement/tally.test.js | 16 +++++++--------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Sprint-2/implement/tally.js b/Sprint-2/implement/tally.js index 4dbdb47b0..d169c1f7e 100644 --- a/Sprint-2/implement/tally.js +++ b/Sprint-2/implement/tally.js @@ -1,15 +1,12 @@ function tally(array) { - if(!Array.isArray(array)){ + if (!Array.isArray(array)) { throw new Error("Invalid input"); - } + } let obj = {}; array.forEach((elem) => { obj[elem] = (obj[elem] || 0) + 1; }); return obj; } -//console.log(tally("asd")); - - module.exports = tally; diff --git a/Sprint-2/implement/tally.test.js b/Sprint-2/implement/tally.test.js index e7e4c2685..c4a934900 100644 --- a/Sprint-2/implement/tally.test.js +++ b/Sprint-2/implement/tally.test.js @@ -1,7 +1,7 @@ const tally = require("./tally.js"); /** - * tally array + * tally array * * In this task, you'll need to implement a function called tally * that will take a list of items and count the frequency of each item @@ -23,22 +23,20 @@ const tally = require("./tally.js"); // Given an empty array // When passed to tally // Then it should return an empty object -test("when an empty array is passed to tally it returns an empty object",()=>{ - expect(tally([])).toEqual({}) +test("when an empty array is passed to tally it 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( - "when an array with duplicate items is passed to tally , it returns counts for each unique item",()=>{ - expect(tally(["t", "d", 5, "t", 5])).toEqual({ t: 2, d: 1, 5: 2 }); - } -); +test("when an array with duplicate items is passed to tally , it returns counts for each unique item", () => { + expect(tally(["t", "d", 5, "t", 5])).toEqual({ t: 2, d: 1, 5: 2 }); +}); // Given an invalid input like a string // When passed to tally // Then it should throw an error test("when a string is passed to tally it throws error", () => { expect(() => tally("asd")).toThrow("Invalid input"); -}); \ No newline at end of file +}); From 46c15fa148e6e33d671edeadaba5a36e864e0c5d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 15:42:54 +0000 Subject: [PATCH 21/32] fix: correct implementation of invert function to properly swap keys and values, add comments to explain the process --- 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..5a1d14277 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; } +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} +//{"1":"a","2":"b"} // c) What does Object.entries return? Why is it needed in this program? +//it returns the key:value pairs of obj,it's needed to extract those pairs from obj // d) Explain why the current return value is different from the target output +//because it's using invertedObj.key = value; instead of invertedObj[value] = key; // e) Fix the implementation of invert (and write tests to prove it's fixed!) From b6692593be475e8e132561eeb2fd5aeedb7a037f Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 15:43:22 +0000 Subject: [PATCH 22/32] test: add initial test suite for invert function --- Sprint-2/interpret/invert.test.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) 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..e69de29bb From 4c94700ca8d6b2ea381e571bb70d8045a35c2c21 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 15:51:32 +0000 Subject: [PATCH 23/32] fix: add input validation to invert function to handle non-object inputs and improve error handling --- Sprint-2/interpret/invert.js | 4 +++- Sprint-2/interpret/invert.test.js | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index 5a1d14277..2d3e410ae 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -7,6 +7,7 @@ // E.g. invert({x : 10, y : 20}), target output: {"10": "x", "20": "y"} function invert(obj) { + if(typeof obj!=="object" || Array.isArray(obj)|| obj===null)throw new Error("Invalid input"); const invertedObj = {}; for (const [key, value] of Object.entries(obj)) { @@ -15,7 +16,8 @@ function invert(obj) { return invertedObj; } -console.log(invert({a:1,b:2})); +console.log(invert(null)); +module.exports=invert // a) What is the current return value when invert is called with { a : 1 } //{key=1} diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index e69de29bb..858c6ce86 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -0,0 +1,4 @@ +const invert=require("./invert.js") +test("when passed a string invert will throw error",()=>{ + expect(()=>invert("asd")).toThrow("Invalid input") +}) \ No newline at end of file From b80bd10cef22d64bf3377c01b9d6afa01740531d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 16:02:45 +0000 Subject: [PATCH 24/32] fix: update invert function test to handle null input and ensure proper error handling --- Sprint-2/interpret/invert.js | 2 +- Sprint-2/interpret/invert.test.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index 2d3e410ae..b1e6331e0 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -16,7 +16,7 @@ function invert(obj) { return invertedObj; } -console.log(invert(null)); +console.log(invert({})); module.exports=invert // a) What is the current return value when invert is called with { a : 1 } diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 858c6ce86..327413ab4 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -1,4 +1,5 @@ const invert=require("./invert.js") test("when passed a string invert will throw error",()=>{ expect(()=>invert("asd")).toThrow("Invalid input") -}) \ No newline at end of file +}) + From 5b1dab3e92f11e53226932d376c7102de184af65 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 16:15:32 +0000 Subject: [PATCH 25/32] test: add additional test cases for invert function to validate behavior with various inputs --- Sprint-2/interpret/invert.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 327413ab4..6c79bb29f 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -3,3 +3,14 @@ test("when passed a string invert will throw error",()=>{ expect(()=>invert("asd")).toThrow("Invalid input") }) +test("when passed an empty object, invert returns an empty object",()=>{ + expect(invert({})).toEqual({}) +}) + +test("when passed an object containing one key:value pair, invert returns an object containing value:key", () => { + expect(invert({a:1})).toEqual({"1":"a"}); +}); + +test("when passed an object containing multiple key:value pairs, invert returns an object containing value:key pairs", () => { + expect(invert({ a: 1,apple:"red",month:"September" })).toEqual({ 1: "a","red":"apple","September":"month" }); +}); \ No newline at end of file From 9935333615332309297d1e919841fa002bdbb09f Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 16:15:56 +0000 Subject: [PATCH 26/32] fix: improve input validation in invert function and update test cases for consistency --- Sprint-2/interpret/invert.js | 7 ++++--- Sprint-2/interpret/invert.test.js | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Sprint-2/interpret/invert.js b/Sprint-2/interpret/invert.js index b1e6331e0..25de7b376 100644 --- a/Sprint-2/interpret/invert.js +++ b/Sprint-2/interpret/invert.js @@ -7,7 +7,8 @@ // E.g. invert({x : 10, y : 20}), target output: {"10": "x", "20": "y"} function invert(obj) { - if(typeof obj!=="object" || Array.isArray(obj)|| obj===null)throw new Error("Invalid input"); + if (typeof obj !== "object" || Array.isArray(obj) || obj === null) + throw new Error("Invalid input"); const invertedObj = {}; for (const [key, value] of Object.entries(obj)) { @@ -16,8 +17,8 @@ function invert(obj) { return invertedObj; } -console.log(invert({})); -module.exports=invert + +module.exports = invert; // a) What is the current return value when invert is called with { a : 1 } //{key=1} diff --git a/Sprint-2/interpret/invert.test.js b/Sprint-2/interpret/invert.test.js index 6c79bb29f..56c6aef71 100644 --- a/Sprint-2/interpret/invert.test.js +++ b/Sprint-2/interpret/invert.test.js @@ -1,16 +1,20 @@ -const invert=require("./invert.js") -test("when passed a string invert will throw error",()=>{ - expect(()=>invert("asd")).toThrow("Invalid input") -}) +const invert = require("./invert.js"); +test("when passed a string invert will throw error", () => { + expect(() => invert("asd")).toThrow("Invalid input"); +}); -test("when passed an empty object, invert returns an empty object",()=>{ - expect(invert({})).toEqual({}) -}) +test("when passed an empty object, invert returns an empty object", () => { + expect(invert({})).toEqual({}); +}); test("when passed an object containing one key:value pair, invert returns an object containing value:key", () => { - expect(invert({a:1})).toEqual({"1":"a"}); + expect(invert({ a: 1 })).toEqual({ 1: "a" }); }); test("when passed an object containing multiple key:value pairs, invert returns an object containing value:key pairs", () => { - expect(invert({ a: 1,apple:"red",month:"September" })).toEqual({ 1: "a","red":"apple","September":"month" }); -}); \ No newline at end of file + expect(invert({ a: 1, apple: "red", month: "September" })).toEqual({ + 1: "a", + red: "apple", + September: "month", + }); +}); From 12de278a96ac0a9720aef66aa01198e8d9fe15ec Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 17:19:47 +0000 Subject: [PATCH 27/32] refactor: split calculateMode into smaller functions for improved readability --- Sprint-2/stretch/mode.js | 14 +++++++++++--- Sprint-2/stretch/mode.test.js | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Sprint-2/stretch/mode.js b/Sprint-2/stretch/mode.js index 3f7609d79..d7f149f48 100644 --- a/Sprint-2/stretch/mode.js +++ b/Sprint-2/stretch/mode.js @@ -9,7 +9,12 @@ // into smaller functions using the stages above function calculateMode(list) { - // track frequency of each value + let freqs = elementFrequency(list); + + return maxFrequency(freqs); +} + +function elementFrequency(list) { let freqs = new Map(); for (let num of list) { @@ -19,8 +24,10 @@ function calculateMode(list) { freqs.set(num, (freqs.get(num) || 0) + 1); } + return freqs; +} - // Find the value with the highest frequency +function maxFrequency(freqs) { let maxFreq = 0; let mode; for (let [num, freq] of freqs) { @@ -29,8 +36,9 @@ function calculateMode(list) { maxFreq = freq; } } - return maxFreq === 0 ? NaN : mode; } + + module.exports = calculateMode; diff --git a/Sprint-2/stretch/mode.test.js b/Sprint-2/stretch/mode.test.js index ca33c28a3..1f2d72353 100644 --- a/Sprint-2/stretch/mode.test.js +++ b/Sprint-2/stretch/mode.test.js @@ -9,7 +9,7 @@ const calculateMode = require("./mode.js"); // Example: // Given [2,4,1,2,3,2,1] // When calculateMode is called on [2,4,1,2,3,2,1] -// Then it should return 2 */ +// Then it should return 2 */ describe("calculateMode()", () => { test("returns the most frequent number in an array", () => { From fad45bea9a8ce4a3690cb802aa5c1ffa29bf2785 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 22:00:55 +0000 Subject: [PATCH 28/32] fix: implement countWords function to count word occurrences in a string --- Sprint-2/stretch/count-words.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-2/stretch/count-words.js b/Sprint-2/stretch/count-words.js index 8e85d19d7..7ce05352b 100644 --- a/Sprint-2/stretch/count-words.js +++ b/Sprint-2/stretch/count-words.js @@ -26,3 +26,15 @@ 3. Order the results to find out which word is the most common in the input */ +function countWords(string) { + const noPunctuation = string.replace(/[.,!?]/g,""); + const array = noPunctuation.split(" "); + + + let object = {}; + array.forEach((word) => { + object[word] = (object[word] || 0) + 1; + }); + return array +} +console.log(countWords("you, and .me? and you me me")); From fe23a35290787b22a3eb49228728849221a19b00 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 22:03:24 +0000 Subject: [PATCH 29/32] fix: ensure case-insensitive word counting and return correct object in countWords function --- Sprint-2/stretch/count-words.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/stretch/count-words.js b/Sprint-2/stretch/count-words.js index 7ce05352b..1faaa32a2 100644 --- a/Sprint-2/stretch/count-words.js +++ b/Sprint-2/stretch/count-words.js @@ -28,13 +28,13 @@ */ function countWords(string) { const noPunctuation = string.replace(/[.,!?]/g,""); - const array = noPunctuation.split(" "); + const array = noPunctuation.toLowerCase().split(" "); let object = {}; array.forEach((word) => { object[word] = (object[word] || 0) + 1; }); - return array + return object } -console.log(countWords("you, and .me? and you me me")); +console.log(countWords("You, and .me? and you me me")); From 6fc416e92d0d6cbdb14af766c78a74a509bc150d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 27 Feb 2026 22:15:17 +0000 Subject: [PATCH 30/32] fix: update countWords function to return sorted word counts --- Sprint-2/stretch/count-words.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/stretch/count-words.js b/Sprint-2/stretch/count-words.js index 1faaa32a2..6ab05ee67 100644 --- a/Sprint-2/stretch/count-words.js +++ b/Sprint-2/stretch/count-words.js @@ -35,6 +35,6 @@ function countWords(string) { array.forEach((word) => { object[word] = (object[word] || 0) + 1; }); - return object + return Object.values(object).sort((a,b)=>b-a)/////?????? stuck on how to order it } console.log(countWords("You, and .me? and you me me")); From 6e3ea519f44a4831d0472ef9b1a601005ced7d60 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 1 Mar 2026 12:03:46 +0000 Subject: [PATCH 31/32] fix: correct total calculation in totalTill function by parsing coin values --- Sprint-2/stretch/till.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Sprint-2/stretch/till.js b/Sprint-2/stretch/till.js index 6a08532e7..7f926ad82 100644 --- a/Sprint-2/stretch/till.js +++ b/Sprint-2/stretch/till.js @@ -8,7 +8,10 @@ function totalTill(till) { let total = 0; for (const [coin, quantity] of Object.entries(till)) { - total += coin * quantity; + const coinWithOutTrailingP = coin.slice(0, -1); + const numberCoin = +coinWithOutTrailingP; + + total += numberCoin * quantity; } return `£${total / 100}`; @@ -21,11 +24,29 @@ const till = { "20p": 10, }; const totalAmount = totalTill(till); +console.log(totalAmount); // a) What is the target output when totalTill is called with the till object +//£4.40 // b) Why do we need to use Object.entries inside the for...of loop in this function? +// to get the key value pairs // c) What does coin * quantity evaluate to inside the for...of loop? +//NaN // d) Write a test for this function to check it works and then fix the implementation of totalTill +// const till1 = { +// "1p": 10, +// "5p": 6, +// "50p": 4, +// "20p": 10, +// }; + +const currentOutput = totalTill(till); +const expectedOutput = "£4.4"; + +console.assert( + currentOutput === expectedOutput, + `Expected ${expectedOutput}, got ${currentOutput}` +); From 24a4c748c44fb7f0ab1509531348e5ea2ef1cf0e Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 12 Mar 2026 10:58:45 +0000 Subject: [PATCH 32/32] fix: update contains function to throw error for empty objects instead of returning false --- Sprint-2/implement/contains.js | 11 +++++++---- Sprint-2/implement/contains.test.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index f5ee45f31..58f57414e 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,10 +1,13 @@ function contains(obj, propertyName) { - if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { + if ( + typeof obj !== "object" || + obj === null || + Array.isArray(obj) || + Object.keys(obj).length === 0 + ) { throw new Error("Invalid object"); } - if (Object.keys(obj).length === 0) { - return false; - } + if (Object.keys(obj).includes(propertyName)) { return true; } diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index ce132b050..699a3fccf 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -21,7 +21,7 @@ as the object doesn't contains a key of 'c' // When passed to contains // Then it should return false test("contains on empty object and propertyName='k' returns false", () => { - expect(contains({}, "k")).toEqual(false); + expect(()=>contains({}, "k")).toThrow("Invalid object"); }); // Given an object with properties