Repository navigation
London | 26-ITP-Sep | Mahir Shah | Sprint 2 | Sprint 2 coursework - #1505
MahirShah300 wants to merge 19 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
9d3ca30 to
cfa87df
Compare
| test("given something that isn't an object, throw error", () => { | ||
| expect(() => contains([1,2,5])).toThrow( | ||
| Error("contains requires an object") | ||
| ); | ||
| }); |
There was a problem hiding this comment.
Why not use a formatter to keep the code consistently formatted? (The spacing around the array elements is not consistent).
There was a problem hiding this comment.
Used prettier to format everything
| (Object.getPrototypeOf(objToCheck) !== Object.prototype && | ||
| Object.getPrototypeOf(objToCheck) !== null) |
There was a problem hiding this comment.
Note: This check would also reject objects created as new Map(), Object.create( {} ), and many other types of object. If you just want to check whether objToCheck is an array, there is a more direct approach.
There was a problem hiding this comment.
Changed the check to Array.isArray(objToCheck) to check if it is an Array
|
|
||
| function contains(objToCheck, keyToSearch) { | ||
| checkIfObj(objToCheck); | ||
| return Object.keys(objToCheck).includes(keyToSearch); |
There was a problem hiding this comment.
const obj = { 0: 123 };
// Output false true 123
console.log(contains(obj, 0), contains(obj, '0'), obj[0]);When a non-string value is used as a key, it is implicitly converted to its string equivalent. However, the code on line 14 treats any non-string keyToSearch as different from its string equivalent.
A better approach would be to use one of Object's built-in methods. Could you find out what this method is?
There was a problem hiding this comment.
Used Object.hasOwn(objToCheck, keyToSearch) to check because it does conversions automatically
| for (const pair of countryCurrencyPairs) { | ||
| objCountryCurrencyPairs[pair[0]] = pair[1]; | ||
| } |
There was a problem hiding this comment.
Why not use array destructuring syntax to make the code more readable?
There was a problem hiding this comment.
Changed to for (const [country, currency] of countryCurrencyPairs) { objCountryCurrencyPairs[country] = currency; }
| if (!pair.includes("=")) { | ||
| const key = decodeURIComponent(pair).replace("+", " "); | ||
| queryParams[key] = ""; | ||
| } else { | ||
| const key = decodeURIComponent(pair.slice(0, pair.indexOf("="))).replace( | ||
| "+", | ||
| " " | ||
| ); | ||
| const value = decodeURIComponent( | ||
| pair.slice(pair.indexOf("=") + 1) | ||
| ).replace("+", " "); |
There was a problem hiding this comment.
Could you check if parseQueryString('a=x%2By)` is returning the value you expect?
There was a problem hiding this comment.
It doesn't, because I was decoding and then replacing, which removed the + character. I now replace + characters first, then decode
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good. Well done.
Learners, PR Template
Self checklist
Task code
CYF-1083
Changelist
Fixed all bugs, implemented functions and answered questions