Skip to content

LONDON | GISLAINE DELLA BELLA | Module-Data-Groups | Week-2 #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

Della-Bella
Copy link

Learners, PR Template

Self checklist

  • [X ] I have committed my files one by one, on purpose, and for a reason
  • [X ] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • [X ] I have tested my changes
  • [X ] My changes follow the style guide
  • [X ] My changes meet the requirements of this task

Changelist

Good evening, Volunteer,
Here are my code exercises from Week 2. I'm still finding it a little confusing, but I’m getting better at reading and explaining the code. However, I’m not completely comfortable writing everything on my own just yet.
Thank you for your time and support,
Gislaine

Questions

Ask any questions you have for your reviewer.

@Della-Bella Della-Bella added the Needs Review Participant to add when requesting review label Dec 12, 2024
@cjyuan cjyuan added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Dec 21, 2024
Copy link
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.

Code is pretty solid.

I left a few comments. I marked the more important ones with Todo .

Note: Your current branch also contains modified files in the Sprint-1 folder.

// Check if the object is valid and has the property

function contains(obj, property) {
if (typeof obj === "object" && obj !== null && property in obj) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion
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( obj.hasOwnProperty(propertyName) );   // false

Which of these approaches suits your needs better?
For more info, you can look up JS "in" operator vs hasOwnProperty.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my search - Key Difference

  • Use in if you want to check all properties, including inherited ones.
  • Use hasOwnProperty if you only care about the object's own properties.

What I understood I should use “hasOwnProperty “as I want to check only on the object and not on inherited ones. But the description says I need to check using “in”. ?

Therefore chnaging the function to:

function contains(obj, property) { // Check if obj is an object (not null) and not an array if ( typeof obj === "object" && obj !== null && Object.prototype.hasOwnProperty.call(obj, property) ) { return true; // Property exists as an own property } return false; // Property doesn't exist or obj is not a valid object }

it fails when rejecting checking if t is an Array.

Comment on lines +7 to +9
return true;
} else {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (condition === true)
  return true;
else
  return false;

could be simplified as return (condition === true);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function contains(obj, property) {
// Check if obj is an object (not null) and not an array
if (
typeof obj === "object" && obj !== null &&!Array.isArray(obj) && property in obj
) {
return (condition === true);
} else {
return false;
}
} // when I change to return (condition === true); one of my codes fail.

Comment on lines +23 to +24
const arrayInput = ["value1", "value2"];
expect(contains(arrayInput, "key")).toBe(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo
Can you try also expect(contains(arrayInput, "1")).toBe(false);?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Cjyuan,
I have add!Array.isArray(obj) for the arrays to be considered as aa "object".

Test Suites: 1 passed, 1 total
Tests: 5 passed, 5 total

expect(result).toEqual(expectedTally); // Check if the result matches the expected output
});


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one test?

Comment on lines +27 to +30
// '1': 'a', '2': 'b',

// c) What is the target return value when invert is called with {a : 1, b: 2}
//key: 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: Can you recheck the answers to questions (b) and (c)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a) What is the current return value when invert is called with { a : 1 }= return is { '1': 'a' }

b) What is the current return value when invert is called with { a: 1, b: 2 } = { '1': 'a', '2': 'b' }

c) What is the target return value when invert is called with {a : 1, b: 2} = { '1': 'a', '2': 'b' }

const input = { a: 1, b: 2 };
const expected = { 1: "a", 2: "b" };
expect(invert(input)).toEqual(expected);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you expect from invert( { a: 1, b: 1 } )?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will return true.

@@ -8,24 +8,25 @@ function totalTill(till) {
let total = 0;

for (const [coin, quantity] of Object.entries(till)) {
total += coin * quantity;
// Remove 'p' and convert to number
const numericCoin = parseInt(coin.replace("p", ""), 10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseInt() can also work on the string value of coin without first removing "p" from the string. You may want to find out how parseInt() work.

}

return queryParams;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo
For each of the following function calls, does your function return the value you expected?

parseQueryString("a=b&=&c=d")
parseQueryString("a=")
parseQueryString("=b")
parseQueryString("a=b&&c=d")
parseQueryString("a%25b=c%26d`)

Note: the %25 and %26 are URL encoded or percent encoded characters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Cyuan,
I did make some changes but honestly, it is another level to me. I'm studying these days JS things I kow I left behind and theses tests are one of them.

@cjyuan cjyuan added 👀 Review Git Changes requested to do with Git Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Dec 21, 2024
@Della-Bella Della-Bella added the Complete Volunteer to add when work is complete and review comments have been addressed label Jan 15, 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 review comments have been addressed 👀 Review Git Changes requested to do with Git Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants