Skip to content

Manchester | 26-ITP-Sep | Precious Moses | Sprint 2 | Data Groups - #1497

Open
moses77-boop wants to merge 48 commits into
CodeYourFuture:mainfrom
moses77-boop:Sprint-2
Open

moses77-boop wants to merge 48 commits into
CodeYourFuture:mainfrom
moses77-boop:Sprint-2

Conversation

@moses77-boop

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

Task code

CYF-1083

Changelist

In this PR, I debugged, interpreted codes, implemented tests and wrote functions to complete this coursework.

@moses77-boop moses77-boop 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 Nov 6, 2026
Comment on lines +35 to +45
test("contains throws an error for an array", () => {
expect(() => contains([1, 2, 3], "name")).toThrow(
"contains requires an object"
);
});

test("contains throws an error for a string", () => {
expect(() => contains("Manchester", "name")).toThrow(
"contains requires an 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.

Your current function implementation is good, but our tests (in practice) should not only verify our current implementation, but also ensure that future changes do not alter the function's expected behavior.

Arrays are objects, with their indices acting as keys.

Object.hasOwn([1, 2, 3], 'name')        // evaluates to false
Object.hasOwn([1, 2, 3], '0')           // evaluates to true

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

The same also apply to string.

Comment on lines +50 to +53
// Edge cases
test("should not crash on malformed percent-encoding", () => {
expect(parseQueryString("a=%E0%A4%A")).toEqual({ a: "%E0%A4%A" });
});

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.

Nice edge case consideration.

Comment on lines +6 to +14
const counts = {};

for (const item of items) {
if (counts[item] === undefined) {
counts[item] = 1;
} else {
counts[item] += 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.

When using a regular object as a dictionary or map, we should consider whether a key might match the name of an inherited property.

For example, 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(), or
  • use a Map object

Comment on lines 13 to +17
// a) What is the current return value when invert is called with { a : 1 }
// Current return value is 1.

// b) What is the current return value when invert is called with { a: 1, b: 2 }
// The current return value is 2.

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.

I think the question is asking what the original function returns when the parameter is the specified object.
Does the function return a number or an object?

@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 Nov 8, 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