Sheffield | ITP-Jan-26 | Hayriye Saricicek | Sprint 2 | Module-Data-Groups#1099
Sheffield | ITP-Jan-26 | Hayriye Saricicek | Sprint 2 | Module-Data-Groups#1099mshayriyesaricicek wants to merge 5 commits intoCodeYourFuture:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
You missed updating Sprint-2/interpret/invert.js.
| @@ -1,3 +1,8 @@ | |||
| function contains() {} | |||
| function contains(obj, key) { | |||
| if (typeof obj !== "object" || Array.isArray(obj)) { | |||
There was a problem hiding this comment.
Unfortunately typeof null was mistakenly evaluated to "object" in the language, and they cannot change that now.
| if (typeof obj !== "object" || Array.isArray(obj)) { | ||
| throw new Error("Input must not be an array"); | ||
| } | ||
| return key in obj; |
There was a problem hiding this comment.
Consider the following two approaches for determining if an object contains a property:
let obj = {}, propertyName = "toString";
console.log( propertyName in obj ); // true
console.log( Object.hasOwn(obj, propertyName) ); // false
Which of these approaches suits your needs better?
For more info, you can look up JS "in" operator vs Object.hasOwn.
| const [key, value] = pair.split("="); | ||
| const [key, ...rest] = pair.split("="); | ||
| const value = rest.join("="); | ||
| queryParams[key] = value; |
There was a problem hiding this comment.
Note: (No change required)
-
In real query string, both
keyandvalueare percent-encoded or URL encoded in the URL.
For example, the string "5%" is encoded as "5%25". So to get the actual value of "5%25"
(whether it is a key or value in the query string), we need to call a function to decode it. -
You can also explore the
URLSearchParamsAPI.
| const result = {}; | ||
|
|
||
| for (const item of arr) { | ||
| if (item in result) { | ||
| result[item] = result[item] + 1; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
Self checklist
Changelist
Exercises for Sprint 2