-
-
Notifications
You must be signed in to change notification settings - Fork 222
West Midlands | 25 Sep ITP | Iswat Bello | Sprint 2 | Module Data Groups Coursework #856
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
Conversation
- returns true if object has property - returns false if property missing or object empty - throws TypeError for invalid inputs
…ect; import invert with require
…ed by another file
… and nested object input
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.
Great work! Comprehensive tests!
I only have a few suggestions.
Sprint-2/implement/tally.js
Outdated
| throw new TypeError("Invalid input: Input must be an array"); | ||
| } | ||
|
|
||
| const result = {}; |
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.
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.
No, it did not return the expected value.
expected value: {"toString": 2}
actual value: "toString": "function toString() { [native code] }11".
I would look up an approach to create an empty object with no inherited properties.
| const index = pair.indexOf("="); | ||
| let key, value; | ||
|
|
||
| if (index === -1) { | ||
| key = pair; | ||
| value = ""; | ||
| } else { | ||
| key = pair.slice(0, index); | ||
| value = pair.slice(index + 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".
Sprint-2/implement/contains.test.js
Outdated
| expect(() => contains("hello", "location")).toThrow( | ||
| new TypeError("Invalid input: obj must be a plain object") | ||
| ); | ||
| expect(() => contains(null, "a")).toThrow( | ||
| new TypeError("Invalid input: obj must be a plain object") | ||
| ); | ||
| expect(() => contains(undefined, "a")).toThrow( | ||
| new TypeError("Invalid input: obj must be a plain object") | ||
| ); | ||
| expect(() => contains(123, "a")).toThrow( | ||
| new TypeError("Invalid input: obj must be a plain object") | ||
| ); | ||
| expect(() => contains(true, "a")).toThrow( | ||
| new TypeError("Invalid input: obj must be a plain object") | ||
| ); | ||
| expect(() => contains([], "a")).toThrow( | ||
| new TypeError("Invalid input: obj must be a plain object") | ||
| ); | ||
| expect(() => contains(() => {}, "a")).toThrow( | ||
| new TypeError("Invalid input: obj must be a plain object") | ||
| ); |
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.
All these tests expect the same error to be thrown.
You could explore using Jest '.each' or similar approach to reduce redundant code.
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.
I have refactored the test and pushed the changes to the remote repo
Sprint-2/debug/recipe.js
Outdated
| for (const ingredient of recipe.ingredients) { | ||
| console.log(ingredient); | ||
| } |
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.
You may also like Array.prototype.join().
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.
I have updated the code to use Array.prototype.join() instead of the loop I used before.
Thank you very much. |
…oString affecting expected results
…ithout prototype conflicts
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.
Other changes look good.
Sprint-2/implement/querystring.js
Outdated
|
|
||
| if (decodeURI(queryString) === decodeURIComponent(queryString)) { | ||
| queryString = decodeURIComponent(queryString); | ||
| } | ||
|
|
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.
There may be special characters such as = and & encoded in the keys or values. If you decode the entire query string at this point, the = and & that are part of some keys or values will be mistaken for separators.
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.
Thank you for the feedback. I have fixed the code to decode after splitting.
… and throw descriptive error for invalid URL encoding
|
Great work! |
Thank you so much @cjyuan for reviewing my pull request and providing detailed feedback. |
Learners, PR Template
Self checklist
Changelist
This pull request includes modifications to three directories:
Debug directory: I identified and fixed bugs in each file within the debug section by first predicting the issue, then running the code with Node to confirm the behaviour. All implementations were corrected so that they now pass the associated test cases.
Implement directory: I implemented functions based on the given requirements and ensured they work across a variety of inputs. I followed the recommended order (contains → lookup → tally → querystring) and created or updated corresponding test cases for each.
Interpret directory: I interpreted larger programs with unfamiliar syntax or operators using documentation and console logging. I refactored the implementations for clarity and reliability while ensuring all existing tests continued to pass.
Questions
Hi. Please could you review my PR? I’d really appreciate your feedback.