Skip to content

ITP -Northwest- JAN 2025 | Jan Lo | Module-Data groups | SPRINT 2 | WEEK 7 #506

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 3 commits into
base: main
Choose a base branch
from

Conversation

JanLlw
Copy link

@JanLlw JanLlw commented Apr 20, 2025

Learners, PR Template

Self checklist

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

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@JanLlw JanLlw added the Needs Review Participant to add when requesting review label Apr 20, 2025
Copy link

@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 good.

contains() could use some fixing.

Comment on lines 1 to 20
function contains(element, key) {
const result = element[key];

// console.log({
// key,
// typeKey: typeof key,

// result,
// typeResult: typeof result
// })

// if undefined
// return false as doesnt exist
// else, does exist!
// return true

if (result === undefined) return false;
else return true;

}
Copy link

Choose a reason for hiding this comment

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

This approach is not bulletproof because a property can be assigned an undefined value. For example,

  let obj { x: undefined };  // An object with a property named "x", and its value is undefined.

Can you figure out how else to improve the code?

Comment on lines +42 to +45
test("invalid parameters", () => {
expect(contains(["apple", "orange", "pear"])).toBe (false);
});

Copy link

Choose a reason for hiding this comment

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

Invalid parameters could also be other types of values. For examples, null, "some string", 123, undefined.

With your current implementation, contains(["apple", "orange", "pear"], "0") and contains("ABC", "0") would return true`.

You would need to add code to your function to check the first parameter is a valid object and is not an array.

Note: array is a kind of objects in JS.

Comment on lines 10 to 11
const value = valueParts.join("=");
queryParams[key] = value;
Copy link

Choose a reason for hiding this comment

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

Your approach works.

Please note that in real querystring, both key and value are percent-encoded or URL encoded in the URL. For example, the string "5%" will be encoded as "5%25". So to get the actual value of "5%25" (whether it is a key or value in the querystring), you should call a function to decode it.
May I suggest looking up any of these terms, and "How to decode URL encoded string in JS"?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Apr 21, 2025
@JanLlw JanLlw added the Needs Review Participant to add when requesting review label Apr 21, 2025
@cjyuan
Copy link

cjyuan commented Apr 22, 2025

Changes look good.

@cjyuan
Copy link

cjyuan commented Apr 22, 2025

It is good practice to respond to each reviewer's comment to acknowledge their feedback and to explain any changes made in response.

image

@cjyuan
Copy link

cjyuan commented Apr 22, 2025

It's also a good practice to give a brief description to each PR.

image

@cjyuan cjyuan added Complete Participant to add when work is complete and review comments have been addressed and removed Needs Review Participant to add when requesting review Reviewed Volunteer to add when completing a review labels Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Participant to add when work is complete and review comments have been addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants