-
-
Notifications
You must be signed in to change notification settings - Fork 279
London | 26-ITP-Jan | Miriam Jorna | Sprint 2 | Data Groups #1190
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
b9c0a55
a3b820b
f5c978a
30de7d5
b3b0ea7
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, property) { | ||
| if (Array.isArray(obj) || typeof obj !== "object" || obj === null) { | ||
| return false; | ||
| } | ||
| return obj.hasOwnProperty(property); | ||
| } | ||
|
|
||
| module.exports = contains; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(pairs) { | ||
| const lookup = {}; | ||
| for (const [country, currency] of pairs) { | ||
| lookup[country] = currency; | ||
| } | ||
| return lookup; | ||
| } | ||
|
|
||
| module.exports = createLookup; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,9 @@ function parseQueryString(queryString) { | |
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| const index = pair.indexOf("="); | ||
| const key = pair.slice(0, index); | ||
| const value = pair.slice(index + 1); | ||
|
Comment on lines
+9
to
+11
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. For each of the following function calls, does your function return the value you expect? parseQueryString("key1=value1&=&key2=value2")
parseQueryString("key=")
parseQueryString("key1=value1&key2")
parseQueryString("=value")
parseQueryString("key1=value1&&key2=value2") |
||
| queryParams[key] = value; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,16 @@ | ||
| function tally() {} | ||
| function tally(arr) { | ||
| if (!Array.isArray(arr)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
| const result = {}; | ||
| for (const item of arr) { | ||
| if (result[item]) { | ||
| result[item]++; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| } | ||
|
Comment on lines
+5
to
+12
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:
|
||
| 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.
Your function is correct, but we should prepare tests not only to verify our current implementation, but also to ensure that future changes do not alter the function's expected behavior.
This test cannot yet confirm that the function correctly returns false when the first argument is an array.
This is because
contains([1, 2, 3], "a")could also returnfalsesimply because "a" is not a key of the array.Arrays are objects, with their indices acting as keys. A proper test should use a valid key to ensure the function returns
falsespecifically because the input is an array, not because the key is missing.