-
-
Notifications
You must be signed in to change notification settings - Fork 276
Sheffield | ITP-Jan-26 | Hayriye Saricicek | Sprint 2 | Module-Data-Groups #1099
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?
Changes from all commits
4418392
066d615
f033f1c
e1308fd
859028e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| function contains() {} | ||
| function contains(obj, key) { | ||
| if (typeof obj !== "object" || Array.isArray(obj)) { | ||
| throw new Error("Input must not be an array"); | ||
| } | ||
| return key in obj; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider the following two approaches for determining if an object contains a property: Which of these approaches suits your needs better? |
||
| } | ||
|
|
||
| module.exports = contains; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| } | ||
| function createLookup(CountryCurrencyPairs) { | ||
| const result = {}; | ||
|
|
||
| for (const pair of CountryCurrencyPairs) { | ||
| const [country, currency] = pair; | ||
| result[country] = currency; | ||
| } | ||
| return result; | ||
| } | ||
| module.exports = createLookup; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,8 @@ function parseQueryString(queryString) { | |
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| const [key, ...rest] = pair.split("="); | ||
| const value = rest.join("="); | ||
| queryParams[key] = value; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: (No change required)
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,18 @@ | ||
| function tally() {} | ||
| function tally(arr) { | ||
| if (!Array.isArray(arr)) { | ||
| throw new Error("Input must be an array"); //checks input is an array if not throws error | ||
| } | ||
|
|
||
| const result = {}; | ||
|
|
||
| for (const item of arr) { | ||
| if (item in result) { | ||
| result[item] = result[item] + 1; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| } | ||
|
Comment on lines
+6
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the following function call returns the value you expect? Suggestion: Look up an approach to create an empty object with no inherited properties. |
||
|
|
||
| return result; | ||
| } | ||
| module.exports = tally; | ||
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.
Unfortunately
typeof nullwas mistakenly evaluated to "object" in the language, and they cannot change that now.