Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
1977a31
predicted and explained the out put of the code. and the reasons.
Bluejay600 Jul 16, 2025
eebd015
fixed the code and tested the result.
Bluejay600 Jul 16, 2025
71bf7b5
predicted the out put
Bluejay600 Jul 16, 2025
7500e6d
explained why the 'for ...of' loop is not iterating over the object.
Bluejay600 Jul 16, 2025
bb5539d
fixed annd corrected the code.
Bluejay600 Jul 16, 2025
a021930
predicted the out put and explained the code.
Bluejay600 Jul 16, 2025
980a5a7
fixed the code using 'join('\n')' on the ingrediants array.
Bluejay600 Jul 16, 2025
a518149
edited the tile ones again.
Bluejay600 Jul 20, 2025
7d3267f
updated the author.js file.
Bluejay600 Jul 22, 2025
fea80a6
implemented contains function.
Bluejay600 Jul 22, 2025
c26f8a2
implemented test when contains on empty object returns false.
Bluejay600 Jul 22, 2025
ae304c5
implemented test contains on object with existing property returns true.
Bluejay600 Jul 22, 2025
906f106
implemented a test when contains on object with non-existent property…
Bluejay600 Jul 22, 2025
8fce11a
implemented a test when contains on array returns false.
Bluejay600 Jul 22, 2025
1a627a2
implemented a test when contains on array returns false.
Bluejay600 Jul 22, 2025
53feb2e
edited the contains function in contains.js
Bluejay600 Jul 22, 2025
7bd8faa
implemented a lookup function .
Bluejay600 Jul 22, 2025
e989993
removed unwanted space
Bluejay600 Jul 22, 2025
d71ddea
added a test to parses querystring with multiple values.
Bluejay600 Jul 22, 2025
2bd6525
added more edge cases to the test.
Bluejay600 Jul 22, 2025
660818b
fixed test parses querystring with single value.
Bluejay600 Jul 22, 2025
541987d
fixed some tests after runing the test.
Bluejay600 Jul 22, 2025
1ca501f
deleted one test.
Bluejay600 Jul 22, 2025
521a882
implemented the function for tally that except only array input.
Bluejay600 Jul 22, 2025
39eee0c
Edited the given todo test for tally on an empty array returns an emp…
Bluejay600 Jul 22, 2025
63d810b
implemented a test to tally on an array with duplicates returns corre…
Bluejay600 Jul 22, 2025
cf316cd
implemented a test for tally throws an error for non-array input
Bluejay600 Jul 22, 2025
091f560
interpreted all the questions in the invert.js.
Bluejay600 Jul 23, 2025
41da9c9
fixed the implementation of invert.
Bluejay600 Jul 23, 2025
6e14892
added the the module.experts= invert; at the last line.
Bluejay600 Jul 23, 2025
31426cd
created a new file test.js to write the test code in it for the inver…
Bluejay600 Jul 23, 2025
0e06b4f
implemented a function in the test.js file to Help function to compar…
Bluejay600 Jul 23, 2025
071aaf5
added some test cases for the function.
Bluejay600 Jul 23, 2025
b7ea301
added the console.log code to test my outputs.
Bluejay600 Jul 23, 2025
4bf8565
deleted the test file after testing for it gives undefiend result.
Bluejay600 Jul 23, 2025
677b56d
added five test cases to for the function created.
Bluejay600 Jul 23, 2025
9c357bd
deleted all the changes in the mode.js and mode.test.js
Bluejay600 Jul 23, 2025
417a3df
Wrote a function called countWords that takes a string as an argument…
Bluejay600 Jul 23, 2025
24a64ca
added console.log statement to test the function's results.
Bluejay600 Jul 23, 2025
b23ddc3
answered the frist till.js question what is the target output?.
Bluejay600 Jul 23, 2025
c2610ef
answered Why do we need to use Object.entries inside the for...of loo…
Bluejay600 Jul 23, 2025
5e9c886
answered What does coin * quantity evaluate to inside for loop.
Bluejay600 Jul 23, 2025
f7c9b83
Fixed the totaltill function implementation.
Bluejay600 Jul 24, 2025
9fda945
1. Edited the return value code to Object.hasOwn(obj, key).
Bluejay600 Jul 30, 2025
25c480d
made the code clearer, by destructure using Object.entries
Bluejay600 Jul 31, 2025
3ef6ee4
edited the function countwords to throw an error if input is string.
Bluejay600 Aug 5, 2025
692ca81
changed code to remove punctuation unsing regex and convert to lowcase.
Bluejay600 Aug 5, 2025
f50f79d
added optional code to Sort the results by frequency.
Bluejay600 Aug 5, 2025
0dde848
added some more examples for testing count-words.js.
Bluejay600 Aug 5, 2025
10af95b
reverted the changes in the quote generator.
Bluejay600 Aug 5, 2025
377da8e
added a robust parseQueryString implementation that passes your tests
Bluejay600 Aug 12, 2025
9cfaa3d
added Split by & and filter out empty chunks (but keep cases like '=')
Bluejay600 Aug 12, 2025
7238ca1
fixed the implementation of the function.
Bluejay600 Aug 12, 2025
9ec23cb
updated code
Bluejay600 Aug 16, 2025
93a7fa7
deleted unwanted code
Bluejay600 Aug 16, 2025
79fe12d
updated the js file code.
Bluejay600 Aug 17, 2025
8f4d096
updated function implementations.
Bluejay600 Aug 17, 2025
0e6590f
Merge branch 'main' into coursework_Sprint-2
Bluejay600 Aug 17, 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
5 changes: 4 additions & 1 deletion Sprint-2/debug/address.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Predict and explain first...
// I think this code will log out "My house number is undefined"
// because address[0] is trying to access an index that doesn't exist in the object.

// This code should log out the houseNumber from the address object
// but it isn't working...
Expand All @@ -12,4 +14,5 @@ const address = {
postcode: "XYZ 123",
};

console.log(`My house number is ${address[0]}`);
console.log(`My house number is ${address.houseNumber}`);
// The code is already correct and will log the house number as expected.
13 changes: 12 additions & 1 deletion Sprint-2/debug/author.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
// Predict and explain first...
// I think this code will not work as expected because the `for...of`
// loop is trying to iterate over an object.
// Objects cannot be iterated directly with `for...of`.

// 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

//JavaScript objects like author aren’t directly iterable with a for...of loop.
//for...of is designed to work with iterable objects like arrays, strings, maps,
// etc. Since author is a plain object, trying to iterate over it like that throws a TypeError.
// To fix this, we can use `Object.values()` to get an array of the object's values
// and then iterate over that array.

const author = {
firstName: "Zadie",
lastName: "Smith",
Expand All @@ -11,6 +20,8 @@ const author = {
alive: true,
};

for (const value of author) {
for (const value of Object.values(author)) {
console.log(value);
}
// This code will now correctly log all the values of the author object.
// The fix was to use Object.values(author) to get an array of the values
8 changes: 7 additions & 1 deletion Sprint-2/debug/recipe.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// Predict and explain first...
// I think this code will log out the title, how many it serves, and the ingredients.
// However, it will not log each ingredient on a new line because the `recipe` object

// 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?
// The code is not correctly logging the ingredients on separate lines.
// To fix this, we can use `join('\n')` on the ingredients array to format them correctly.
// Additionally, we need to ensure that the template literal is formatted correctly.

const recipe = {
title: "bruschetta",
Expand All @@ -12,4 +17,5 @@ const recipe = {

console.log(`${recipe.title} serves ${recipe.serves}
ingredients:
${recipe}`);
${recipe.ingredients.join('\n')}`);
// This code will now correctly log the title, number of servings, and each ingredient on a new line.
7 changes: 6 additions & 1 deletion Sprint-2/implement/contains.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
function contains() {}
function contains(obj, key) {
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
return false;
}
return Object.hasOwn(obj, key);
}

module.exports = contains;
16 changes: 13 additions & 3 deletions Sprint-2/implement/contains.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,29 @@ as the object doesn't contains a key of 'c'
// When passed an object and a property name
// Then it should return true if the object contains the property, false otherwise


// 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 on object 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 on object with non-existent property returns false", () => {
expect(contains({ a: 1, b: 2 }, 'c')).toBe(false);
});

// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
test("contains on array returns false", () => {
expect(contains([1, 2, 3], '1')).toBe(false);
});
14 changes: 13 additions & 1 deletion Sprint-2/implement/lookup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
function createLookup() {
function createLookup(pairs) {
// implementation here
if (!Array.isArray(pairs)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation is a bit off.

throw new Error("Input must be an array of [key, value] pairs");
}

return pairs.reduce((acc, pair) => {
if (!Array.isArray(pair) || pair.length !== 2) {
throw new Error("Each item must be an array with exactly 2 elements");
}
const [countryCode, currencyCode] = pair;
acc[countryCode] = currencyCode;
return acc;
}, {});
}

module.exports = createLookup;
13 changes: 10 additions & 3 deletions Sprint-2/implement/lookup.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +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", () => {
const input = [['US', 'USD'], ['CA', 'CAD'], ['JP', 'JPY']];
const expected = {
US: 'USD',
CA: 'CAD',
JP: 'JPY'
};

expect(createLookup(input)).toEqual(expected);
});
/*

Create a lookup object of key value pairs from an array of code pairs
Expand Down
Loading