Skip to content

London | 26-ITP-May | Raihan Sharif | Sprint 2 | Exercises#1220

Open
RaihanSharif wants to merge 26 commits into
CodeYourFuture:mainfrom
RaihanSharif:sprint-2-exercises
Open

London | 26-ITP-May | Raihan Sharif | Sprint 2 | Exercises#1220
RaihanSharif wants to merge 26 commits into
CodeYourFuture:mainfrom
RaihanSharif:sprint-2-exercises

Conversation

@RaihanSharif
Copy link
Copy Markdown

Learners, PR Template

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

Changelist

Done all exercises. For the invert exercises, made decision to prevent inverting where multiple keys have the same value. e.g. {a: "f", b: "f"} as this would produce {f: "b"}, thereby losing some information.

@RaihanSharif RaihanSharif added 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 May 7, 2026
Comment thread Sprint-2/implement/contains.js Outdated

function contains(object, key) {
if (isObject(object)) {
return key in object;
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.

hasOwn excludes inherited properties. I hadn't considered that we'd want to exclude inherited properties.

I suppose in this case, we do want to exlcude inherited properties.

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 spec didn't specify. So as long as you are aware of the difference, that's enough.


if value at key is an array, and contains the incoming value, ignore. Else, push it to the array.
*/
if (Object.prototype.hasOwnProperty.call(queryParams, key)) {
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 also use Object.hasOwn()

Comment thread Sprint-2/implement/tally.js Outdated
Comment on lines +11 to +13
acc[curr] = (acc[curr] ?? 0) + 1;
return acc;
}, {});
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()

Comment thread Sprint-2/interpret/invert.js Outdated
if (Object.prototype.hasOwnProperty.call(invertedObj, String(value))) {
throw new Error(`Duplicate value "${value}" found — cannot invert`);
}
invertedObj[String(value)] = key;
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.

All values (except Symbol) when used as keys, are converted implicitly to string. So a cast to string is optional.

@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 May 10, 2026
@RaihanSharif RaihanSharif added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels May 10, 2026
@cjyuan
Copy link
Copy Markdown
Contributor

cjyuan commented May 10, 2026

Changes look good. Well done.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Data-Groups The name of the module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants