Skip to content

Manchester | 26-ITP-Jan | Mehroz Munir | Sprint 2 | Coursework#1051

Open
MehrozMunir wants to merge 5 commits intoCodeYourFuture:mainfrom
MehrozMunir:coursework/sprint-2
Open

Manchester | 26-ITP-Jan | Mehroz Munir | Sprint 2 | Coursework#1051
MehrozMunir wants to merge 5 commits intoCodeYourFuture:mainfrom
MehrozMunir:coursework/sprint-2

Conversation

@MehrozMunir
Copy link
Copy Markdown

No description provided.

@MehrozMunir MehrozMunir added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Groups The name of the module. labels Mar 20, 2026
Comment on lines +53 to +55
// CASE 2: Should return an empty object if empty array is passed
test(`should return an empty object if the array is empty`, () =>
expect(createLookup([[]])).toEqual({}));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The first argument is not quite an empty array; it is "an array containing an empty array".

For this input, your function actually returns { undefined: undefined } instead of {}, but toEqual() consider them equal because it ignores property named "undefined". A stricter comparison .toStrictEqual() would have flagged them as an error.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks.
Yes that is absolutely right. Do you think that I should always use toStrictEqual in all the test cases?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes. I think .toStrictEqual() is better when comparing objects.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 25, 2026
@MehrozMunir
Copy link
Copy Markdown
Author

@cjyuan
Thank you for the feedback. I have implemented the changes and pushed the latest code. Kindly check, please.

@MehrozMunir MehrozMunir added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 27, 2026
Comment on lines +22 to +28
function getRecipeIngredients(recipeIngredients) {
let ingredients = "";
for (const element of recipeIngredients) {
ingredients += element + "\n";
}
return ingredients;
}
Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Mar 27, 2026

Choose a reason for hiding this comment

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

Note: This function can be replaced by a single function call to Array.prototype.join().

No change required but that array's method is worth exploring.

// Then it should return false or throw an error
[
{ input: [1], property: "a" },
{ input: [1], property: "0" },
Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Mar 27, 2026

Choose a reason for hiding this comment

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

My concern was just about the test.

We write tests not only to verify our current implementation, but also to ensure that future changes do not alter the function's expected behavior.

So after adding a test such as

{ input: [1], property: "0" },

you can help ensure future modification of the function can still correctly reject array.

Comment on lines +22 to +25
let currentNumberFrequency = frequencyMap.get(number);
if (currentNumberFrequency !== undefined)
frequencyMap.set(number, (currentNumberFrequency += 1));
else frequencyMap.set(number, 1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Could just use + instead of += on line 24.

  • Why not use the original syntax to implement the code on lines 22-25?

frequencyMap.set(number, (frequencyMap.get(number) || 0) + 1);

Comment on lines -33 to +40
return maxFreq === 0 ? NaN : mode;
return maxKey;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The original code returns NaN instead of null when there is no mode.

Comment on lines +43 to +45
.replace(/\s+/g, " ");

cleanText.split(" ").forEach((word) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note: We can also use regex with .split(), and combine the operation on line 43 and 45 as:

  cleanText.split(/\s+/).forEach((word) => {

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Data-Groups The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants