-
-
Notifications
You must be signed in to change notification settings - Fork 191
West Midlands | ITP-Sept-25 | Georgina Rogers | Sprint 2 | Coursework Sprint 2 #862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| for (const pair of pairs) { | ||
| // Iterate over each pair in the input array | ||
| if (Array.isArray(pair) && pair.length >= 2) { | ||
| const [countryCode, currencyCode] = pair; // Destructuring first two elements of pair array and assigning them to country and currency | ||
| lookup[countryCode] = currencyCode; // Add country-currency pair to the lookup object - later entries overwrite earlier ones if duplicate country codes exist. | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is a bit off.
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| queryParams[key] = value; | ||
| // Iterate over each key-value pair | ||
| if (!pair.includes("=")) { | ||
| // Handle missing equals sign | ||
| queryParams[pair] = undefined; // Assign undefined for keys without equals sign | ||
| continue; // Move to the next pair | ||
| } | ||
| const [key, ...rest] = pair.split("="); // array destructured into key and rest of array. | ||
| // Split by '=' to separate key and value. | ||
| const value = rest.join("="); // Join back any '=' in the value using rest operator | ||
| queryParams[key] = value; // Assign key-value pair to the result object | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that in real querystring, both key and value are percent-encoded or URL encoded in the URL. For example, the string "5%" will be encoded as "5%25". So to get the actual value of "5%25" (whether it is a key or value in the querystring), we would need to call a function to decode it.
May I suggest looking up any of these terms, and "How to decode URL encoded string in JS"?
| if (!Array.isArray(items)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
| const counts = {}; // empty object to store tally of key-value pairs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
|
||
| // 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "current return value" in questions (a), (b), and (d) refers to the value returned by the original (unmodified) function.
The objects you described on line 28 and 31 are not the objects returned by the original function.
The explanation given on line 41 (answer to question (d)) is also not quite correct.
Learners, PR Template
Self checklist
Changelist
Bugs predicted, tested and fixed.
Implement functions based off a set of requirements.
Interpret a program.
Questions
.