Skip to content

Sheffield| 26-ITP-Jan| Mona-Eltantawy | Sprint 2 | Sprint 2 course-work tasks#1195

Open
Mona-Eltantawy wants to merge 13 commits intoCodeYourFuture:mainfrom
Mona-Eltantawy:sprint-2-courswork
Open

Sheffield| 26-ITP-Jan| Mona-Eltantawy | Sprint 2 | Sprint 2 course-work tasks#1195
Mona-Eltantawy wants to merge 13 commits intoCodeYourFuture:mainfrom
Mona-Eltantawy:sprint-2-courswork

Conversation

@Mona-Eltantawy
Copy link
Copy Markdown

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

@Mona-Eltantawy Mona-Eltantawy added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 11, 2026
Copy link
Copy Markdown
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Some of the code is not consistently formatted.

Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode,
as recommended in
https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/blob/main/readme.md
?


If you have enabled "Format on save" but it is not working, it is likely that you haven't assign a formatter for JS file. This could happen if you have zero or multiple extensions that can format .js file.

If you have installed "Prettier" extension. To assign it as the formatter of JS code, you can try:

  1. Use "Format document" to format the JS file. Sometimes, VSCode will ask you to choose a formatter, and you can manually select "Prettier".
  2. Edit settings.json and set Prettier as the default formatter for JS.
    See: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode

Comment thread Sprint-2/debug/author.js
Comment on lines +1 to +3
function contains(obj, key) {
return key in obj;
}
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.

Consider the following two approaches for determining if an object contains a property:

  let obj = {}, propertyName = "toString";
  console.log( propertyName in obj );                // true
  console.log( Object.hasOwn(obj, propertyName) );   // false

Which of these approaches suits your needs better?
For more info, you can look up JS "in" operator vs Object.hasOwn.

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.

I understand your point her but the function used still give the required output, so I'm not sure if I have to change it to Object.hasOwn( ) method or to keep it.

Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Apr 14, 2026

Choose a reason for hiding this comment

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

Have you found out the difference between key in object and Object.hasOwn(object, key)?

As long as you know their differences, you can use either approach in your implementation because the spec is not clear exactly how the function should behave.

Comment thread Sprint-2/implement/contains.test.js
Comment thread Sprint-2/implement/tally.js Outdated
Comment on lines +5 to +8
const result ={ };
for (let item of items){
result[item]=(result[item] || 0)+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.

Does the following function call returns the value you expect?

tally(["toString", "toString"]);

Suggestion:

  • Look up an approach to create an empty object with no inherited properties, or
  • use Object.hasOwn()

@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 Apr 12, 2026
@Mona-Eltantawy Mona-Eltantawy added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 14, 2026
Copy link
Copy Markdown
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Can you also address the two unaddressed comments from the previous review?

Comment thread Sprint-2/debug/author.js
Comment on lines +18 to +21
let text = " ";
for (let x in author) {
text+= author[x] + "\n ";
};
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.

Can also explore using Array.prototype.join() to produce exactly the same string in one statement.

Comment on lines +48 to +51
test("contains with invalid parameters return false", () => {
const obj = ["a", "b", "c", "d"];
expect(contains(obj, "a")).toBe(false);
});
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.

Arrays are objects, with their indices acting as keys. That means

  console.log("a" in ['a','b','c','d']);   // output false
  console.log("1" in ['a','b','c','d']);   // output true

A proper test should use a valid
key to ensure the function returns false specifically because the input is an array, not because the key is missing.

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

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants