Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b06cb19
Add mean calculation test
HoussamLh Jul 25, 2025
c9fbbff
Add test for calculateMedian and calculateMean using salaries array
HoussamLh Jul 25, 2025
95f7fd3
Add calculateMedian function with tests for even and odd length arrays
HoussamLh Jul 25, 2025
f02e624
I've done the prep of this sprint 2
HoussamLh Jul 30, 2025
c87010e
access houseNumber property correctly instead of using index
HoussamLh Jul 30, 2025
0b3bd51
iterate over object values correctly to log all properties
HoussamLh Jul 30, 2025
5c03c87
correctly log recipe ingredients on separate lines
HoussamLh Jul 30, 2025
9059809
implement 'contains' function to check property existence in objects
HoussamLh Jul 30, 2025
a0ec1e9
add 'createLookup' function scaffold and test placeholder
HoussamLh Jul 30, 2025
32172e4
- improve 'parseQueryString' function to handle '=' in values correctly
HoussamLh Jul 30, 2025
5b4d5eb
- implement 'tally' function to count frequencies in an array
HoussamLh Jul 30, 2025
a107cbb
- correct property access in address object logging
HoussamLh Jul 30, 2025
1403fb7
- iterate over object values correctly in author.js
HoussamLh Jul 30, 2025
f88fb4e
- Properly log recipe ingredients on separate lines
HoussamLh Jul 30, 2025
1f315ef
- correct invert function to swap object keys and values
HoussamLh Jul 31, 2025
8b66d38
- implement countWords function with punctuation removal and case ins…
HoussamLh Jul 31, 2025
629e898
- split calculateMode into getFrequencies and findMode helper functions
HoussamLh Jul 31, 2025
429338b
- correctly calculate totalTill by parsing coin strings
HoussamLh Jul 31, 2025
0cc0eec
Merge branch 'CodeYourFuture:main' into CourseWork-Sprint-2
HoussamLh Sep 7, 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
10 changes: 8 additions & 2 deletions Sprint-2/debug/address.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// Predict and explain first...
// The code is trying to log the houseNumber from the address object.
// But it uses address[0], which tries to access the property with key "0".
// Since address is an object with keys like "houseNumber", "street", etc., there is no property 0.
// Therefore, address[0] will be undefined.
// The console will output:
// My house number is undefined

// This code should log out the houseNumber from the address object
// but it isn't working...
// Fix anything that isn't working


const address = {
houseNumber: 42,
street: "Imaginary Road",
Expand All @@ -12,4 +18,4 @@ const address = {
postcode: "XYZ 123",
};

console.log(`My house number is ${address[0]}`);
console.log(`My house number is ${address.houseNumber}`);
7 changes: 6 additions & 1 deletion Sprint-2/debug/author.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Predict and explain first...
// The code attempts to loop over author using for...of.
// But for...of works on iterable objects like arrays, strings, Maps, Sets.
// Plain objects ({}) are NOT iterable, so for (const value of author) will throw a TypeError:
// author is not iterable.

// 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 +15,7 @@ const author = {
alive: true,
};

for (const value of author) {

for (const value of Object.values(author)) {
console.log(value);
}
8 changes: 6 additions & 2 deletions Sprint-2/debug/recipe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Predict and explain first...
// The current console.log outputs ${recipe}, which converts the whole recipe object to a string as "[object Object]".

// This program should log out the title, how many it serves and the ingredients.
// Each ingredient should be logged on a new line
Expand All @@ -11,5 +12,8 @@ const recipe = {
};

console.log(`${recipe.title} serves ${recipe.serves}
ingredients:
${recipe}`);
ingredients:`);

for (const ingredient of recipe.ingredients) {
console.log(ingredient);
}
9 changes: 8 additions & 1 deletion Sprint-2/implement/contains.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
function contains() {}
function contains(obj, prop) {
// Check if obj is a non-null object and not an array
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
return false;
}
// Use Object.prototype.hasOwnProperty to check for the property
return Object.prototype.hasOwnProperty.call(obj, prop);
}

module.exports = contains;
29 changes: 27 additions & 2 deletions Sprint-2/implement/contains.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
const contains = require("./contains.js");

test("contains on empty object returns false", () => {
expect(contains({}, "anyKey")).toBe(false);
});

test("contains returns true for existing property", () => {
const obj = { a: 1, b: 2 };
expect(contains(obj, "a")).toBe(true);
expect(contains(obj, "b")).toBe(true);
});

test("contains returns false for non-existent property", () => {
const obj = { a: 1, b: 2 };
expect(contains(obj, "c")).toBe(false);
expect(contains(obj, "z")).toBe(false);
});

test("contains returns false or throws for invalid parameters", () => {
expect(() => contains([], "a")).not.toThrow();
expect(contains([], "a")).toBe(false);
expect(() => contains(null, "a")).not.toThrow();
expect(contains(null, "a")).toBe(false);
expect(() => contains(undefined, "a")).not.toThrow();
expect(contains(undefined, "a")).toBe(false);
expect(() => contains(123, "a")).not.toThrow();
expect(contains(123, "a")).toBe(false);
});

/*
Implement a function called contains that checks an object contains a
particular property
Expand All @@ -20,8 +47,6 @@ 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");

// Given an object with properties
// When passed to contains with an existing property name
// Then it should return true
Expand Down
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 lookup = {};
for (const [country, currency] of pairs) {
lookup[country] = currency;
}
return lookup;
}

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


/*

Expand Down
Loading
Loading