-
-
Notifications
You must be signed in to change notification settings - Fork 193
London | ITP-SEP-25 | Samuel Tarawally | Sprint 2 | Coursework/sprint 2 #894
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
base: main
Are you sure you want to change the base?
Conversation
…r object properties
cjyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert the changes made in the "Sprint-3" folder to keep this branch clean?
|
|
||
| // Handles invalid inputs gracefully | ||
| test("contains handles invalid parameters", () => { | ||
| expect(contains([], "a")).toBe(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arrays are objects in JavaScript, and they do have property names -- just not the same ones as objects.
Which keys do arrays have, and how does that affect how reliable your test is?
When testing whether the function handles arrays properly, try using a key that an array might
realistically contain. Otherwise, you might get a passing test even if the function isn't checking for arrays at all.
| for (const pair of arrayOfPairs) { | ||
| const key = pair[0]; | ||
| const value = pair[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also consider using array destructuring to simplify this 3 lines of code.
| const firstEqualsIndex = pair.indexOf("="); | ||
|
|
||
| const key = pair.slice(0, firstEqualsIndex); | ||
| const value = pair.slice(firstEqualsIndex + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the query string is "key1&key2" (i.e., without =)?
| const key = pair.slice(0, firstEqualsIndex); | ||
| const value = pair.slice(firstEqualsIndex + 1); | ||
|
|
||
| queryParams[key] = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In real query string, both key and value are percent-encoded or URL encoded.
For example,
tags%5B%5D=hello%20world-> key istags[], value ishello world
Can your function handle URL-encoded query string?
Suggestion: Look up "How to decode a URL-encoded string in JavaScript".
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| const countObject = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Learners, PR Template
Self checklist
Changelist
address.js,author.js, andrecipe.jscontains,lookup,tally, andquerystringfunctions with testsinvert.js