Skip to content

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

Open
Mona-Eltantawy wants to merge 11 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 11 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 on lines +18 to +26
let text = " ";
for (let x in author) {
text+= author[x] + " ";
};
console.log(text);

// or:
const values = Object.values(author);
console.log(values);
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 attempts to output the value one by one on a new line.
Can you rewrite your code to also output all the property values one by one on a new line?

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 fixed it.

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.

Comment on lines 45 to +51
// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
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.

This test cannot yet confirm that the function correctly returns false when the first argument is an array.
This is because contains(['a','b','c','d'], "a") could also return false simply because "a" is not a key of the array.

Arrays are objects, with their indices acting as keys. 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.

Besides array, you should also test other invalid parameters such as null, undefined, strings, to ensure your function works correctly.

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