Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
5ce7d15
Add if condition to check list is odd or even.
russom-g Nov 3, 2026
8f51f4c
Add sort method to to sort list.
russom-g Nov 3, 2026
d68c02b
Add if condition to check empty array.
russom-g Nov 3, 2026
f65276c
Write test cases for testing empty and no duplicate arrays
russom-g Nov 3, 2026
6745e82
Implement function to check for empty and duplicated arrays.
russom-g Nov 3, 2026
20d911a
Write a test for testing original occurrence returned
russom-g Nov 3, 2026
6f7f6d4
Fix bug where item pushed instead of list
russom-g Nov 3, 2026
a922943
Format code with prettier.
russom-g Nov 3, 2026
2491759
Implement try catch function to return error messages.
russom-g Nov 4, 2026
697d23f
Write test cases for multiple arrays
russom-g Nov 4, 2026
33ffd60
Write test case for findMax with empty array
russom-g Nov 5, 2026
b471137
Write test case for findMax with one number array
russom-g Nov 5, 2026
434ca4b
Implement function for checking array the largest element
russom-g Nov 5, 2026
d997797
Add for and if condition for checking non-array and non-number elements
russom-g Nov 5, 2026
734381d
Write test cases for finMax with different input.
russom-g Nov 5, 2026
215a119
Write test case for calculateMean with array of numbers.
russom-g Nov 6, 2026
c12fb12
implement function to calculate mean of list.
russom-g Nov 6, 2026
31ba3f1
Write test case for calculateMean with a single number array
russom-g Nov 6, 2026
eb978b1
Write test case for calculateMean with negative or decimal numbers.
russom-g Nov 6, 2026
9a8945a
Add Number method to round mean to 2 decimal place
russom-g Nov 6, 2026
68b854a
Write test for calculateMean with empty array.
russom-g Nov 6, 2026
1f53630
Add if condition for checking empty array.
russom-g Nov 6, 2026
d0b0c30
Write test case for calculateMean with no argument
russom-g Nov 6, 2026
c0cc6b7
Add if condition for checking non array.
russom-g Nov 6, 2026
5da7996
Add if condition for checking non-number array.
russom-g Nov 6, 2026
b772767
Write test case for calculateMean with non-number array
russom-g Nov 6, 2026
1374324
Format code with prettier
russom-g Nov 7, 2026
2b9d397
Implement function for calculating sum.
russom-g Nov 7, 2026
1c95b32
Write test case for sum with an empty array.
russom-g Nov 7, 2026
2f02e30
Write test case for sum with one number array.
russom-g Nov 7, 2026
1735942
Add if condition to check array is number.
russom-g Nov 7, 2026
351f97b
Write test case for sum with empty array
russom-g Nov 7, 2026
7bb3a8f
Add if condition for checking non-array elements.
russom-g Nov 7, 2026
15e8f9f
Write test case for sum with non-array element.
russom-g Nov 7, 2026
6c1939d
Refactor includes with for...of loops
russom-g Nov 7, 2026
db24d03
Implement function read .txt file and sum up the result and returns
russom-g Nov 8, 2026
7b407a4
Change to bracket notation to access houseNumber
russom-g Nov 10, 2026
b953e7c
Change to Object.value method to iterate through author object.
russom-g Nov 10, 2026
585cfe1
Print ingredient in separate lines.
russom-g Nov 10, 2026
63eae52
Format code with prettier.
russom-g Nov 10, 2026
f025f5a
Implement contain function returning false.
russom-g Nov 10, 2026
0764465
Add test for contain with empty object.
russom-g Nov 10, 2026
d638679
Update contain function to check empty object
russom-g Nov 10, 2026
cfdd9cc
Implement contains function to check for valid object properties
russom-g Nov 11, 2026
6308c6c
Add test for contains with different property object
russom-g Nov 11, 2026
a1e5834
Implement country lookup function
russom-g Nov 11, 2026
b1d7fb5
Write test for country lookup function
russom-g Nov 11, 2026
1330dc8
Update function to parse = values
russom-g Nov 11, 2026
28f60e5
Update function to ignore empty properties
russom-g Nov 12, 2026
2974d2c
Update function to decode percent-encoded characters
russom-g Nov 12, 2026
036874d
Fix function for tests to pass
russom-g Nov 13, 2026
b6ae9d4
Write test for tally function with empty array
russom-g Nov 13, 2026
ff4a00c
Implement tally function to return empty object
russom-g Nov 13, 2026
68bc523
Add test for tally with duplicate items
russom-g Nov 14, 2026
7a43172
Add test for tally with invalid input
russom-g Nov 14, 2026
d5ddc5f
Update function to count items
russom-g Nov 14, 2026
101c8dd
Update function to check for non-array input
russom-g Nov 14, 2026
697cfff
Update test to fix bug
russom-g Nov 14, 2026
9e4a322
Formate code with prettier
russom-g Nov 14, 2026
dde2ce1
Add test for tally with array of items
russom-g Nov 14, 2026
37b6945
Fix invert function to wap keys and values
russom-g Nov 15, 2026
97bc04a
Write test for invert function with object
russom-g Nov 15, 2026
7d1731d
Add test for invert with empty object
russom-g Nov 15, 2026
78ba804
Add test for invert with single and multiple properties objects
russom-g Nov 15, 2026
5d3a0c9
Add test for invert with string value object
russom-g Nov 15, 2026
c3a87fb
Update function to check non-object input
russom-g Nov 16, 2026
bbd2717
Add test for invert with invalid input
russom-g Nov 16, 2026
571ce4e
Remove Sprint 1 files from Sprint 2 branch
russom-g Nov 16, 2026
ca45fa0
Ignore Sprint 1 files
russom-g Nov 16, 2026
f8dd126
Restore Sprint 1 files
russom-g Nov 16, 2026
1a0d169
Remove gitignore file
russom-g Nov 16, 2026
f8d29b6
Restore gitignore file
russom-g Nov 16, 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
5 changes: 4 additions & 1 deletion Sprint-2/debug/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ const address = {
postcode: "XYZ 123",
};

console.log(`My house number is ${address[0]}`);
console.log(`My house number is ${address["houseNumber"]}`);
// Predict: reference error will be returned.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does address[0] produce in the original code, and what does this corrected lookup produce?

To "like" or "dislike" this comment, please follow this link

// Explain: to access the houseNumber property either dot or bracket notation is needed.
// Solution: address.houseNumber or address["houseNumber"]
5 changes: 4 additions & 1 deletion Sprint-2/debug/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const author = {
alive: true,
};

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

// Predict: it will return undefined.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when you run this loop now, and does that match the prediction that it returns undefined?

To "like" or "dislike" this comment, please follow this link

// Explain: objects values are accessed by including Object.values(author)
17 changes: 15 additions & 2 deletions Sprint-2/debug/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,18 @@ const recipe = {
};

console.log(`${recipe.title} serves ${recipe.serves}
ingredients:
${recipe}`);
ingredients:
${recipe.ingredients.join("\n")}`);

// prediction: the above code prints:
// bruschetta
// serves 2
// ingredients:

//On a new line it prints:
// title: "bruschetta",
// serves: 2,
// ingredients: "olive oil", "tomatoes", "salt", "pepper"

// Explain: on line 15 recipe is missing .ingredients.
// As a result it will print the whole property of recipe object.
Comment on lines +21 to +28

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments describe the pre-fix template, but the current template prints each ingredient on its own line and no longer prints the recipe object. The prediction and explanation should match the code now in the file.

To "like" or "dislike" this comment, please follow this link

12 changes: 11 additions & 1 deletion Sprint-2/implement/contains.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function contains() {}
function contains(obj, property) {
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
throw new Error("contains requires an object");
}
for (const key of Object.keys(obj)) {
if (key === property) {
return true;
}
}
return false;
}

module.exports = contains;
15 changes: 14 additions & 1 deletion Sprint-2/implement/contains.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,31 @@ as an array isn't an object
// 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 returns false", () => {
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("contains with existing property 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("contains with a non-existent property 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
// When passed to contains
// Then it should throw Error("contains requires an object")
// (careful: typeof [] and typeof null are both "object")
test("contains on non-object returns contains requires an object", () => {
expect(() => contains(([1, 2, 3], "a"))).toThrow(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What single value does the comma expression inside contains(...) pass to the function?

To "like" or "dislike" this comment, please follow this link

"contains requires an object"
);
});
7 changes: 6 additions & 1 deletion Sprint-2/implement/lookup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
function createLookup() {
function createLookup(countryCurrencyPairs) {
// implementation here
const currencyLookup = {};
for (const [country, currency] of countryCurrencyPairs) {
currencyLookup[country] = currency;
}
return currencyLookup;
}

module.exports = createLookup;
12 changes: 11 additions & 1 deletion Sprint-2/implement/lookup.test.js
Original file line number Diff line number Diff line change
@@ -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", () => {
expect(
createLookup([
["US", "USD"],
["CA", "CAD"],
])
).toEqual({
US: "USD",
CA: "CAD",
});
});

/*

Expand Down
15 changes: 11 additions & 4 deletions Sprint-2/implement/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ function parseQueryString(queryString) {
return queryParams;
}
const keyValuePairs = queryString.split("&");

for (const pair of keyValuePairs) {
const [key, value] = pair.split("=");
queryParams[key] = value;
if (!pair) {
continue;
}
const everything = pair.split("=");
const key = decodeURIComponent(everything.shift().replace(/\+/g, " "));
const value = decodeURIComponent(everything.join("=").replace(/\+/g, " "));
if (queryParams[key]) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to the second a in a=&a=2 with this truthiness check?

To "like" or "dislike" this comment, please follow this link

queryParams[key] = [].concat(queryParams[key], value);
} else {
queryParams[key] = value;
}
}

return queryParams;
}

Expand Down
17 changes: 16 additions & 1 deletion Sprint-2/implement/tally.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
function tally() {}
function tally(list) {
if (!Array.isArray(list)) {
throw new Error("tally requires an array");
}

const itemFrequencyCount = {};

for (const item of list) {
if (Object.hasOwn(itemFrequencyCount, item)) {
itemFrequencyCount[item] = itemFrequencyCount[item] + 1;
} else {
itemFrequencyCount[item] = 1;
}
}
return itemFrequencyCount;
}

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("tally on an array of items returns the count", () => {
expect(tally(["a", "a", "b", "c", ])).toEqual({ a: 2, b:1, c: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("tally with duplicate items return duplicate counts", () => {
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
// Then it should throw Error("tally requires an array")
test("tally with invalid input returns tally requires an array", () => {
expect(() => tally("list", 2, " ")).toThrow("tally requires an array");
});
13 changes: 12 additions & 1 deletion Sprint-2/interpret/invert.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,34 @@
// E.g. invert({x : 10, y : 20}), target output: {"10": "x", "20": "y"}

function invert(obj) {
if (typeof obj !== "object") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when invert(null) reaches this guard, and which error does the function intend to report for invalid input?

To "like" or "dislike" this comment, please follow this link

throw new Error("invert requires a valid input");
}
const invertedObj = {};

for (const [key, value] of Object.entries(obj)) {
invertedObj.key = value;
invertedObj[value] = key;
}

return invertedObj;
}

module.exports = invert;

// a) What is the current return value when invert is called with { a : 1 }
// - undefined.

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

// 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 turns object properties into an array of key-value pairs

// d) Explain why the current return value is different from the target output
// - line 13 is accessing the property 'key' name directly
// - the target output is to swap properties inside the variable 'key' and 'value'

// e) Fix the implementation of invert (and write tests to prove it's fixed!)
41 changes: 41 additions & 0 deletions Sprint-2/interpret/invert.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const invert = require("./invert.js");

// Empty object
test("invert on an empty object returns an empty object", () => {
expect(invert({})).toEqual({});
});

// Basic objects
test("invert on basic object returns inverted properties object ", () => {
expect(invert({ x: 10, y: 20 })).toEqual({ 10: "x", 20: "y" });
});

// Single property
test("invert on a single property object returns inverted key-value object", () => {
expect(invert({ a: 1 })).toEqual({ 1: "a" });
});

// Multiple properties
test("invert on multiple properties object returns inverted properties object", () => {
expect(invert({ 1: "a", 2: "b", 3: "c", 4: "d" })).toEqual({
a: "1",
b: "2",
c: "3",
d: "4",
});
});

// String values
test("invert on string value object returns inverted key-value object", () => {
expect(invert({ a: "hello" })).toEqual({ hello: "a" });
});

// Duplicate values
test("invert on duplicate values object return inverted object", () => {
expect(invert({ a: 1, b: 1 })).toEqual({ 1: "a", 1: "b" });
});

// Invalid input
test("invert on invalid input returns invert requires a valid input", () => {
expect(() => invert()).toThrow("invert requires a valid input");
});
Loading