Repository navigation
London | 26-ITP-Sep | Chandramani Gaire | Sprint 2 | Module-Data-Group - #1515
gaireprakash20-ops wants to merge 22 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
gaireprakash20-ops
left a comment
There was a problem hiding this comment.
please review this file
| if (decodedKey in queryParams) { | ||
| if (Array.isArray(queryParams[decodedKey])) { | ||
| queryParams[decodedKey].push(decodedValue); | ||
| } else { | ||
| queryParams[decodedKey] = [queryParams[decodedKey], decodedValue]; |
There was a problem hiding this comment.
What happens when a query string contains a key such as toString or __proto__? Does in here distinguish keys already parsed from properties inherited by queryParams?
To "like" or "dislike" this comment, please follow this link
There was a problem hiding this comment.
I replaced the empty object {} with Object.create(null) to prevent inherited properties such as toString and proto. I replaced the in operator with Object.hasOwn() to check only properties that belong directly to the object. These changes make the query-string parser safer and handle special keys more reliably.
| test("contains on empty object returns false", () => { | ||
| expect(contains({}, "name")).toBe(false); | ||
| }); |
There was a problem hiding this comment.
Now that this case has an implementation test, what will Jest still report from the earlier test.todo? The same leftover TODO is present in lookup.test.js.
To "like" or "dislike" this comment, please follow this link
There was a problem hiding this comment.
i remove the TODO from lookup.test.js
There was a problem hiding this comment.
Please also remove the TODO from this file as well. Otherwise, Jest library would still not showing a pass. Thank you.
| // ==>It turns an object into an array of [key, value] pairs. Object.entries({ a: 1, b: 2 }) gives [["a", 1], ["b", 2]]. It’s needed because a for...of loop can’t go through a plain object directly, and the function needs both the key and the value of each property. Object.entries provides both, and const [key, value] unpacks each pair. | ||
| // d) Explain why the current return value is different from the target output | ||
|
|
||
| // ==>first it used the dot notation instead of square bracket which is accessing the property using a literal name |
There was a problem hiding this comment.
Does the issue with invertedObj.key come from dot notation itself, or from which property name that expression accesses?
To "like" or "dislike" this comment, please follow this link
There was a problem hiding this comment.
explain why the current return value is different from the target output
|
The CYF AI review has left comments. It will only review a PR one time. When you have addressed these comments, please request review again and a volunteer will take a look. |
…ner object creation
hackertainment
left a comment
There was a problem hiding this comment.
I can see that you have a strong sense of edge cases. Just need to clear the concept between object and prototype. Maybe book a mentored coding session with a volunteer if that helps. You are almost there and just a minor fix. Please keep it up. Thank you.
| test("contains on empty object returns false", () => { | ||
| expect(contains({}, "name")).toBe(false); | ||
| }); |
There was a problem hiding this comment.
Please also remove the TODO from this file as well. Otherwise, Jest library would still not showing a pass. Thank you.
| for (const item of items) { | ||
| const key = String(item); | ||
|
|
||
| if (Object.prototype.hasOwnProperty.call(counts, key)) { |
There was a problem hiding this comment.
In the future, try to avoid manipulate the prototype directly as it may create side effect to objects of the same type (which could make the code harder to maintain). Your statement is actually the same as if (counts.hasOwnProperty(key)) { which just touches the object but not prototype.
There was a problem hiding this comment.
Delete the todo file line 26 and and Use Object.hasOwn instead of Object.prototype.hasOwnProperty for better readability
| Object.defineProperty(counts, key, { | ||
| value: 1, | ||
| writable: true, | ||
| enumerable: true, | ||
| configurable: true, | ||
| }); |
There was a problem hiding this comment.
This code segment also directly access the prototype. You may just need counts[key] = 1; so that it just touches the object but not prototype.
There was a problem hiding this comment.
Remove the use of object
| test("tally counts numbers and booleans by their string form", () => { | ||
| expect(tally([1, 1, 2, true, true])).toEqual({ 1: 2, 2: 1, true: 2 }); | ||
| }); | ||
|
|
||
| test("tally treats different cases as different items", () => { | ||
| expect(tally(["a", "A", "a"])).toEqual({ a: 2, A: 1 }); | ||
| }); | ||
|
|
||
| test("tally does not change the array it is given", () => { | ||
| const input = ["a", "b", "a"]; | ||
| tally(input); | ||
| expect(input).toEqual(["a", "b", "a"]); | ||
| }); |
There was a problem hiding this comment.
Very good coverage for having these 3 test cases.
| test("inverting twice gives back the original when values are unique strings", () => { | ||
| const original = { a: "x", b: "y" }; | ||
| expect(invert(invert(original))).toEqual(original); | ||
| }); |
There was a problem hiding this comment.
Interesting test case, very good!
gaireprakash20-ops
left a comment
There was a problem hiding this comment.
i did all review question
|
Congratulation, you have completed this PR successfully. |
Learners, PR Template
Self checklist
Task code
CYF-1083
Changelist
I have done all the course work and created new file for the Invert.js ans have pushed it along with the rest of file