London | 26-ITP-Jan | Maryanne Mosonik | Sprint 2 | Module Data Groups#1101
London | 26-ITP-Jan | Maryanne Mosonik | Sprint 2 | Module Data Groups#1101Maryanne-K wants to merge 13 commits intoCodeYourFuture:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
test.todo(" ... ") is just a placeholder to serve as a reminder for "what needs to be done".
In this exercise, that means "implementing the corresponding Jest tests described in the comments."
Can you replace them (in all .test.js files) with actual Jest tests?
| console.log(`${recipe.title} serves ${recipe.serves} | ||
| ingredients: | ||
| ${recipe}`); | ||
| ${recipe.ingredients}`); |
There was a problem hiding this comment.
The requirement on line 4 has not yet been met:
Each ingredient should be logged on a new line
| if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) { | ||
| return false; | ||
| } | ||
| 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.
| } else { | ||
| const key = pair.substring(0, index); | ||
| const value = pair.substring(index + 1); | ||
| 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 counts = {}; | ||
| for (const item of arr) { | ||
| if (counts[item]) { | ||
| counts[item] += 1; | ||
| } else { | ||
| counts[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
Corrected and completed the implementations and jest test cases.