Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
71fa218
Add initial test file for mean calculations
alexandru-pocovnicu Oct 24, 2025
927769b
Add mean.js file for mean calculations
alexandru-pocovnicu Oct 24, 2025
a393af9
Remove mean.js and mean.test.js files
alexandru-pocovnicu Oct 26, 2025
256a0bb
Fix address object access to correctly log house number
alexandru-pocovnicu Nov 2, 2025
93dca5e
Fix loop iteration to correctly log author object properties
alexandru-pocovnicu Nov 2, 2025
538d536
Fix recipe logging to display ingredients on separate lines
alexandru-pocovnicu Nov 2, 2025
608a2f2
Fix recipe logging format to display title, serves, and ingredients i…
alexandru-pocovnicu Nov 2, 2025
3a82eed
Add test case for contains function with empty object
alexandru-pocovnicu Nov 2, 2025
dbd5551
Implement contains function to check for property existence in an object
alexandru-pocovnicu Nov 2, 2025
1769faf
Add additional test cases for contains function to cover non-existent…
alexandru-pocovnicu Nov 2, 2025
8fd279f
Add error handling for non-object parameters in contains function
alexandru-pocovnicu Nov 2, 2025
1ff152e
Refactor test cases for contains function for improved readability an…
alexandru-pocovnicu Nov 2, 2025
2982bf2
Fix formatting inconsistencies in contains function for improved read…
alexandru-pocovnicu Nov 2, 2025
cb3b23c
Implement test for createLookup function to validate country-currency…
alexandru-pocovnicu Nov 2, 2025
e56a2bf
Implement createLookup function to map country to currency
alexandru-pocovnicu Nov 2, 2025
3f4a115
Add tests for tally function to validate behavior with empty and inva…
alexandru-pocovnicu Nov 3, 2025
493e3f1
Implement tally function to count occurrences of elements in an array…
alexandru-pocovnicu Nov 3, 2025
577ae89
Refactor query string tests for improved clarity and structure
alexandru-pocovnicu Nov 3, 2025
99caad7
Refactor parseQueryString function for improved handling of empty pai…
alexandru-pocovnicu Nov 3, 2025
f998538
Fix invert function to correctly swap keys and values in the object
alexandru-pocovnicu Nov 3, 2025
e098bba
Add test for invert function to verify key-value swapping behavior
alexandru-pocovnicu Nov 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sprint-2/debug/address.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
6 changes: 3 additions & 3 deletions Sprint-2/debug/author.js
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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]}`);
}
10 changes: 6 additions & 4 deletions Sprint-2/debug/recipe.js
Original file line number Diff line number Diff line change
@@ -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?
Expand All @@ -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}, serves ${recipe.serves}, ingredients:`);

for (const ingredient of recipe.ingredients) {
console.log(ingredient);
}
15 changes: 14 additions & 1 deletion Sprint-2/implement/contains.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
function contains() {}
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;
}

module.exports = contains;
21 changes: 20 additions & 1 deletion Sprint-2/implement/contains.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,39 @@ 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 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.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
// Then it should return true

//<<<both covered already>>
// Given an object with properties
// When passed to contains with a non-existent property name
// Then it should return 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");
});
17 changes: 15 additions & 2 deletions Sprint-2/implement/lookup.js
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 9 additions & 1 deletion Sprint-2/implement/lookup.test.js
Original file line number Diff line number Diff line change
@@ -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" });
});

/*

Expand Down
20 changes: 18 additions & 2 deletions Sprint-2/implement/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;




48 changes: 45 additions & 3 deletions Sprint-2/implement/querystring.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
// });
// });
16 changes: 15 additions & 1 deletion Sprint-2/implement/tally.js
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 12 additions & 1 deletion Sprint-2/implement/tally.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
})
8 changes: 7 additions & 1 deletion Sprint-2/interpret/invert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 4 additions & 0 deletions Sprint-2/interpret/invert.test.js
Original file line number Diff line number Diff line change
@@ -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" });
});
Loading