Repository navigation
London | 26-ITP-Sep | Alan Mak | Sprint 2 | Sprint 2 Coursework - #1590
AlanGit-debug2604 wants to merge 11 commits into
Conversation
| // The code will print 'My house number is undefined', | ||
| // because the template literal attempts to access the houseNumber property as if it were an array element. | ||
| // But this is not the correct way to access object properties. | ||
| // The correct syntax is to use dot notation or bracket notation without the extra brackets. |
There was a problem hiding this comment.
What property does the original address[0] expression read, and how does that compare with this explanation?
To "like" or "dislike" this comment, please follow this link
There was a problem hiding this comment.
It does not read as housenumber , address[0] treid to read as a property named '0'
| // The current return value is different from the target output because the original implementation of invert was not correctly swapping the keys and values. | ||
| // It may have been returning the original object or not handling the key-value pairs properly. The corrected implementation uses Object.entries to iterate over the key-value pairs and constructs a new object with the keys and values swapped, resulting in the desired output. |
There was a problem hiding this comment.
What result would the original invertedObj.key = value assignment produce for an object with two properties, and does that match this explanation?
To "like" or "dislike" this comment, please follow this link
There was a problem hiding this comment.
The values 1 and 2 become string property keys. This matches the explanation: invertedObj[value] = key correctly swaps keys and values. It does not match the claim that the current implementation returns the original object or fails to handle pairs.
|
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. |
hackertainment
left a comment
There was a problem hiding this comment.
Thank you for your coursework. If you need more practice on object/dictionary in JavaScript, please feel free to book a mentored coding session with a volunteer.
| for (const value of author) { | ||
| console.log(value); | ||
| for (const [key, value] of Object.entries(author)) { | ||
| console.log(`${key}: ${value}`); |
There was a problem hiding this comment.
For your reference only, it just needs to print out the values, so console.log(value); is correct.
| throw new Error("contains requires an object"); | ||
| } | ||
|
|
||
| return Object.prototype.hasOwnProperty.call(object, propertyName); |
There was a problem hiding this comment.
For your future reference, whenever possible, do not use prototype function directly. You may simply use return object.hasOwn(propertyName); instead to achieve the same result. Thank you.
| test("creates a lookup for a single code pair", () => { | ||
| expect(createLookup([["GB", "GBP"]])).toEqual({ | ||
| GB: "GBP", | ||
| }); | ||
| }); | ||
|
|
||
| test("returns an empty object when passed an empty array", () => { | ||
| expect(createLookup([])).toEqual({}); | ||
| }); |
| Object.defineProperty(queryParams, key, { | ||
| value, | ||
| enumerable: true, | ||
| configurable: true, | ||
| writable: true, | ||
| }); |
There was a problem hiding this comment.
This will add a property to all Objects of the same type globally (basically everything in JavaScript) but not solely for the queryParams object. Please fix it. Thank you.
| test("should safely parse a __proto__ key", () => { | ||
| const result = parseQueryString("__proto__=safe"); | ||
|
|
||
| expect(Object.prototype.hasOwnProperty.call(result, "__proto__")).toBe(true); | ||
| expect(result.__proto__).toBe("safe"); | ||
| expect(Object.getPrototypeOf(result)).toBe(Object.prototype); | ||
| }); |
There was a problem hiding this comment.
For the same reason from my other comments, please try to fix this test case by not accessing prototype directly. Thank you.
| Object.defineProperty(counts, item, { | ||
| value: 1, | ||
| enumerable: true, | ||
| configurable: true, | ||
| writable: true, | ||
| }); |
There was a problem hiding this comment.
This will add a property to all Objects of the same type globally (basically everything in JavaScript) but not solely for the counts object. Please fix it. Thank you.
| // a) What is the current return value when invert is called with { a : 1 } | ||
| // {1: "a"} | ||
| // b) What is the current return value when invert is called with { a: 1, b: 2 } | ||
|
|
||
| //{"1": "a", "2": "b"} |
There was a problem hiding this comment.
It is asking about the original code before fixing, but not the one after fixed. What would be the result for (a) and (b)? Thank you.
Learners, PR Template
Self checklist
Task code
CYF-1083
Changelist
Completed the Sprint 2 exercises, including debugging and implementing the required functions.