Skip to content

London | 26-ITP-May | Vito Moratti | Sprint 2 | Coursework - #1364

Open
vmoratti wants to merge 18 commits into
CodeYourFuture:mainfrom
vmoratti:Module-Data-Groups/Sprint-2
Open

London | 26-ITP-May | Vito Moratti | Sprint 2 | Coursework#1364
vmoratti wants to merge 18 commits into
CodeYourFuture:mainfrom
vmoratti:Module-Data-Groups/Sprint-2

Conversation

@vmoratti

@vmoratti vmoratti commented Aug 3, 2026

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

Changelist

I attempted all tasks except the stretch

@vmoratti vmoratti added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 3, 2026
Comment thread Sprint-2/debug/author.js Outdated
Comment thread Sprint-2/implement/contains.js Outdated
Comment thread Sprint-2/implement/contains.test.js
Comment thread Sprint-2/implement/tally.js Outdated
@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 Aug 8, 2026
@vmoratti vmoratti added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 9, 2026
Comment on lines 42 to 47
// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
test("contains an object returns true, or false otherwise", () => {
expect(contains([1, 2, 3, 'a'], "a")).toBe(false);
expect(contains([1, 2, 3, 'a'], "0")).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.

Invalid parameters also include values like null, undefined, 1234, true. Could your function also return false when the first argument is one of these values?

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 have added extra validation to the contains() function now.
I believe it was not in the instruction, nor in the tests, that's why i didn't add them initially.

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 9, 2026
Refactor contains function to handle null, undefined, and Number types.
@vmoratti vmoratti added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 9, 2026
Comment thread Sprint-2/implement/contains.js Outdated
module.exports = contains;
function contains(obj, prop) {
const notArray = !Array.isArray(obj);
if (obj === null || Array.isArray(obj) || obj === Number || obj === undefined) {

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.

There are a few more non-object types that should also be rejected. Why not just reject any value that is an array or not an object?

Notes:

  • obj === Number is not the correct syntax to check if obj is a number or not.
  • Look up "How to check if a value is an object in JS"

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 have added more conditions.

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 10, 2026
@vmoratti vmoratti added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 10, 2026

@cjyuan cjyuan left a comment

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.

Changes look good. Well done.

Comment on lines +3 to +9
return typeof value === 'object'
&& value !== null
&& !Array.isArray(value)
&& !(value instanceof RegExp)
&& !(value instanceof Date)
&& !(value instanceof Set)
&& !(value instanceof Map)

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:

There are too many user-defined object types for us to exclude them all.

It's more important to know the trade-off and differences among the different approaches for checking if a value is an object in JavaScript.

@cjyuan cjyuan added 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 Aug 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants