Skip to content

LONDON | MAY 2025 | JESUS DEL MORAL | SPRINT 2 | DATA GROUPS#647

Closed
delmorallopez wants to merge 6 commits intoCodeYourFuture:mainfrom
delmorallopez:Sprint-2
Closed

LONDON | MAY 2025 | JESUS DEL MORAL | SPRINT 2 | DATA GROUPS#647
delmorallopez wants to merge 6 commits intoCodeYourFuture:mainfrom
delmorallopez:Sprint-2

Conversation

@delmorallopez
Copy link
Copy Markdown

Sprint 2 Module Data Groups

@delmorallopez delmorallopez added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jul 18, 2025
Comment thread Sprint-2/implement/contains.js Outdated
return false;
}

return Object.values(input).includes(containsvalues);
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.

You could also 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

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.

To check -- Property name (key) exists, we use propertyName in obj or hasOwn(obj, key)
To check -- Property value exists, we use Object.values(obj).includes(value)

const valueExists = Object.values(input).includes(value);
const keyExists = Object.hasOwn(input, value);

return valueExists || keyExists;

Comment on lines +76 to +88
const input = {
firstName: "Zaida",
lastName: "Smith",
occupation: "writer",
age: 40,
alive: true,
};

const currentOutput = contains(input, "errortest");
const targetOutput = false;

expect(currentOutput).toEqual(targetOutput);

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.

  • Why are these parameters considered invalid?

  • Can you make your function return the following expected result?

  // An array is a kind of object, and its keys are its indexes.
  contains(["A", "B", "C"], "1"); // expect false because the first parameter is an array

  // Empty string can also be key
  contains({ "": "Boo" }, "");  // expect true
  
  contains(null, "null"); // expect false even though type of null is equal to "object"

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.

The parameters are considers invalid because "errortest" is not a Key or value fo the object
I added all the tests considering the expected result on your suggestion

function contains(input, value) {
if (
input === null || // explicitly reject null
typeof input !== 'object' ||
Array.isArray(input) ||
value === undefined || value === null // allow empty string
) {
return false;
}

const valueExists = Object.values(input).includes(value);
const keyExists = Object.hasOwn(input, value);

return valueExists || keyExists;

}

Comment thread Sprint-2/implement/querystring.js Outdated
Comment thread Sprint-2/implement/tally.js Outdated
Comment thread Sprint-2/stretch/count-words.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 Jul 26, 2025
@delmorallopez delmorallopez added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jul 27, 2025
@cjyuan
Copy link
Copy Markdown
Contributor

cjyuan commented Jul 27, 2025

Changes look good! Well done.

  • contains(obj, key) is suppose to just check if the 2nd parameter exists in the first parameter as a key; there is no need to check if the 2nd parameter exists in the first parameter as a value. (No change needed as you already know how to do the checking).

@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 Jul 27, 2025
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.

3 participants