Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0ada3c7
fix: correct address property access in console log
Grajales-K Mar 17, 2026
51fbc93
fix: iterate over author object values instead of object directly
Grajales-K Mar 17, 2026
2af5e52
feat: add for of to print the ingredients logged on a new line
Grajales-K Mar 18, 2026
431ad8d
test: enhance contains function tests for various scenarios
Grajales-K Mar 18, 2026
12b176a
feat: implement contains function to check property existence in objects
Grajales-K Mar 18, 2026
a6db5d0
test: add tests for createLookup function to validate country and cur…
Grajales-K Mar 18, 2026
45eff04
feat: implement createLooKup function to map countries to currencies
Grajales-K Mar 18, 2026
8e727fa
fix: correct implementation of invert function to return expected key…
Grajales-K Mar 18, 2026
bbadd05
feat: simplify ingredient logging by joining array elements
Grajales-K Mar 26, 2026
5954a24
fix: replace property check with Object.hasOwn for better accuracy
Grajales-K Mar 26, 2026
32d596c
test: add test for inherited properties in contains function
Grajales-K Mar 26, 2026
5fb163b
test: add additional tests for non-object parameters in contains func…
Grajales-K Mar 26, 2026
7de3692
fix: enhance query string parsing to handle empty and malformed pairs
Grajales-K Mar 27, 2026
9f2cfaa
fix: improve query string parsing to decode keys and values correctly
Grajales-K Mar 30, 2026
f576b00
test: add tests for query string parsing edge cases
Grajales-K Mar 30, 2026
c8745ab
test: update query string parsing test to cover additional value formats
Grajales-K Mar 31, 2026
f1acefa
test: add unit tests for tally function to validate item counting and…
Grajales-K Mar 31, 2026
65beafc
feat: implement tally function to count items in an array with error …
Grajales-K Mar 31, 2026
9ed9f13
refactor: split calculateMode into smaller functions for improved rea…
Grajales-K Mar 31, 2026
0a6a351
fix: correct coin value calculation and format total output in totalT…
Grajales-K Mar 31, 2026
dace1b2
test: add unit tests for totalTill function to validate coin calculat…
Grajales-K Mar 31, 2026
e100de6
fix: update comments in invert function to clarify return values
Grajales-K Mar 31, 2026
2a4bad9
fix: correct variable name for decoded key in query string parsing
Grajales-K Apr 1, 2026
cbe948e
fix: use Object.create(null) for counts in tally function to avoid pr…
Grajales-K Apr 1, 2026
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
2 changes: 1 addition & 1 deletion Sprint-2/debug/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}`);
6 changes: 5 additions & 1 deletion Sprint-2/debug/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const author = {
alive: true,
};

for (const value of author) {
for (const value of Object.values(author)) {
console.log(value);
}


// It did work because an object is not iterable as an array, but we can use Object.values()
// to get an array of the property values and then iterate over that array.
16 changes: 12 additions & 4 deletions Sprint-2/debug/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
// Each ingredient should be logged on a new line
// How can you fix it?

// it won't work because the last line is calling the object property recipe and we
// need the ingredientes, the console.log is trying to log the whole array of ingredients
// as a string, but we want to log each ingredient on a new line. We can fix this by
// using a for loop to iterate over the ingredients array and log each ingredient separately.

const recipe = {
title: "bruschetta",
title: "Bruschetta",
serves: 2,
ingredients: ["olive oil", "tomatoes", "salt", "pepper"],
};

console.log(`${recipe.title} serves ${recipe.serves}
ingredients:
${recipe}`);
console.log(`Recipe: ${recipe.title} \nserves: ${recipe.serves}`);
for(const ingredient of recipe.ingredients) {
console.log(`${ingredient}`);
}
Comment thread
Grajales-K marked this conversation as resolved.
Outdated


11 changes: 10 additions & 1 deletion Sprint-2/implement/contains.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
function contains() {}
function contains(obj, property) {
if (typeof obj !== "object" || obj === null || Array.isArray(obj)){
return false;
}

return property in obj;
Comment thread
Grajales-K marked this conversation as resolved.
Outdated
}


module.exports = contains;


17 changes: 16 additions & 1 deletion Sprint-2/implement/contains.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,35 @@ 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("return true when an object has the property name", () => {
expect(contains({a: 1, b: 2}, "a")).toBe(true);
})

// Given an empty object
// When passed to contains
// Then it should return false
test.todo("contains on empty object returns false");
test("returns false on empty object ", () => {
expect(contains({}, "a")).toBe(false);
});

// Given an object with properties
// When passed to contains with an existing property name
// Then it should return true
test("return true when pass an object that contains the property name", () => {
expect(contains({name: "John", age: 30}, "name")).toBe(true);
})

// Given an object with properties
// When passed to contains with a non-existent property name
// Then it should return false
test("return false when pass an object that does not contain the property name", () => {
expect(contains({id: 12, status: "active"}, "age")).toBe(false);
})

// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
test("return false when pass an array instead of an object", () => {
expect(contains([1, 2, 3], "name")).toBe(false);
Comment thread
Grajales-K marked this conversation as resolved.
Outdated
expect(contains(null, "prop")).toBe(false);
})
8 changes: 6 additions & 2 deletions Sprint-2/implement/lookup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
function createLookup() {
// implementation here
function createLookup(pairs) {
const result = {};
for(const [country, currency] of pairs) {
result[country] = currency;
}
return result
}

module.exports = createLookup;
18 changes: 17 additions & 1 deletion Sprint-2/implement/lookup.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const createLookup = require("./lookup.js");

test.todo("creates a country currency code lookup for multiple codes");

/*

Expand Down Expand Up @@ -33,3 +32,20 @@ It should return:
'CA': 'CAD'
}
*/

test("return an object with country codes as keys and currency codes as values", () => {
expect( createLookup([ ["MX", "MXN"], ["JP", "JPY"] ])).toEqual({ MX: "MXN", JP: "JPY"});
expect( createLookup([ ["AU", "AUD"], ["CH", "CHF"] ])).toEqual({ AU: "AUD", CH: "CHF" });
});

describe("return an object with country codes as keys and currency codes as values", () => {
[
{ input: [["US", "USD"],["CA", "CAD"]], expected: { US: "USD", CA: "CAD" } },
{ input: [["GB", "GBP"],["FR", "EUR"]], expected: { GB: "GBP", FR: "EUR" } },
{ input: [["JP", "JPY"],["AU", "AUD"]], expected: { JP: "JPY", AU: "AUD" } },
].forEach(({ input, expected }) => {
it(`should convert ${JSON.stringify(input)} into ${JSON.stringify(expected)}`, () => {
expect(createLookup(input)).toEqual(expected);
});
});
});
44 changes: 37 additions & 7 deletions Sprint-2/interpret/invert.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,50 @@ 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 }
console.log(invert({ a: 1, b: 2 })); // Expected output: { '1': 'a', '2': 'b' }

// b) What is the current return value when invert is called with { a: 1, b: 2 }

// c) What is the target return value when invert is called with {a : 1, b: 2}

// c) What does Object.entries return? Why is it needed in this program?
/*
a) What is the current return value when invert is called with { a : 1 }
*the value { key: 1 }

b) What is the current return value when invert is called with { a: 1, b: 2 }
*the first pair is { key: 1 }
*and the second pair the value is { key: 'b' } that means the first pair is
being overwritten by the second pair, so the final return value is { key: 'b' }
Comment thread
Grajales-K marked this conversation as resolved.
Outdated

c) What is the target return value when invert is called with {a : 1, b: 2}
*the target return value is { "1": "a", "2": "b" }

d) What does Object.entries return? Why is it needed in this program?
*Return value: It returns an array of arrays, where each sub-array is a [key, value]
pair (e.g., [['a', 1]]).
*Why it's needed: Objects are not iterables by default. We need Object.entries
to convert the object into an array so we can use the for...of loop to go through each pair.

e) Explain why the current return value is different from the target output
*Literal Property Creation: The current code uses dot notation (invertedObj.key),
which creates a property literally named "key" instead of using the value stored
inside the key variable.

*Overwriting: Because it keeps targetting the same literal property name ("key"),
each iteration overwrites the previous one. This is why the final object only contains
the last value processed.

*Target vs. Current: The target output requires bracket notation (invertedObj[value])
to dynamically assign the new keys based on the input's values.


f) Fix the implementation of invert (and write tests to prove it's fixed!)
expect({ a: 1, b: 2 })toEqual({ '1': 'a', '2': 'b' } ) now is working as expected

**/

// d) Explain why the current return value is different from the target output

// e) Fix the implementation of invert (and write tests to prove it's fixed!)
Loading