-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
base: main
Are you sure you want to change the base?
Conversation
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.
Code is good.
contains()
could use some fixing.
Sprint-2/implement/contains.js
Outdated
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; | ||
|
||
} |
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.
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?
test("invalid parameters", () => { | ||
expect(contains(["apple", "orange", "pear"])).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.
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.
Sprint-2/implement/querystring.js
Outdated
const value = valueParts.join("="); | ||
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.
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"?
Changes look good. |
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.