Repository navigation
Conversation
| const list_of_items= {}; | ||
|
|
||
| for (const item of items) { | ||
| if (list_of_items [item]) { |
There was a problem hiding this comment.
What does list_of_items[item] return on the first occurrence of an item such as "toString"?
To "like" or "dislike" this comment, please follow this link
There was a problem hiding this comment.
An empty object inherits properties from Object.prototype, so checking "toString" returns an inherited function. I've changed the object to Object.create(null) to avoid this issue.
| return invertedObj; | ||
| } | ||
|
|
||
| console.log(invert); |
There was a problem hiding this comment.
What output appears whenever a test or another module imports this file?
To "like" or "dislike" this comment, please follow this link
There was a problem hiding this comment.
I've made the correction and updated the currency mapping to GBP.
| const countryCurrencyPairs = [ | ||
| ["US", "USD"], | ||
| ["CA", "CAD"], | ||
| ["GB", "GPB"], |
There was a problem hiding this comment.
The fixture uses GPB for GB, and the expected object repeats that value, so this test accepts the wrong currency code. What code should this mapping use?
To "like" or "dislike" this comment, please follow this link
|
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. |
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(countryCurrencyPairs) { | ||
| const c_Lookup = {}; |
There was a problem hiding this comment.
Two things to look at. JavaScript convention for variables is camelCase, so what would this name look like without the underscore? Also, what does the c stand for, and would a reader know without asking?
| key = decodeURIComponent(key.replace(/\+/g, " ")); | ||
| value = decodeURIComponent(value.replace(/\+/g, " ")); |
There was a problem hiding this comment.
The same two-step transformation (replace then decodeURIComponent) is written twice. Would a small, well-named helper give you one place to change the rule? Also compare replace(/\+/g, " ") with replaceAll("+", " "). Is the regex buying you anything here?
There was a problem hiding this comment.
Created a reusable "decodeFormValue()" helper to avoid duplication and replaced the regex with the simpler "replaceAll()" method.
| if (!Array.isArray(items)) { | ||
| throw new Error("tally requires an array"); | ||
| } | ||
| const list_of_items= Object.create(null); |
There was a problem hiding this comment.
JavaScript convention for variables is camelCase, so what would this name look like without the underscores?
There was a problem hiding this comment.
Updated variable names to follow camelCase convention, replacing underscores and unclear abbreviations with descriptive names.
| throw new Error("tally requires an array"); | ||
| } | ||
| const list_of_items= Object.create(null); | ||
| // const list_of_items= {}; |
There was a problem hiding this comment.
Make sure to always remove dead code before submitting.
| // When passed to tally | ||
| // Then it should throw Error("tally requires an array") | ||
|
|
||
| test("throws an error for a string", () => { |
There was a problem hiding this comment.
The name says “a string”, but the test also covers a number and no argument at all.
There was a problem hiding this comment.
Updated the test name to cover all invalid inputs: a string, a number, or no argument.
Task code
CYF-1083
Changelist
Debugged, implemented and interpreted the code across multiple files.