-
-
Notifications
You must be signed in to change notification settings - Fork 279
Sheffield| 26-ITP-Jan| Mona-Eltantawy | Sprint 2 | Sprint 2 course-work tasks #1195
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
ddf0157
d9a0ef0
f5fa493
5d9c49d
07f2e56
93e9e87
fffec28
6e578a4
5cba6b1
da48732
1f6e611
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,5 @@ | ||
| function contains() {} | ||
| function contains(obj, key) { | ||
| return key in obj; | ||
| } | ||
|
Comment on lines
+1
to
+3
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?
Author
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. I understand your point her but the function used still give the required output, so I'm not sure if I have to change it to
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. Have you found out the difference between As long as you know their differences, you can use either approach in your implementation because the spec is not clear exactly how the function should behave. |
||
|
|
||
| module.exports = contains; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,16 +20,35 @@ as the object doesn't contains a key of 'c' | |
| // Given an empty object | ||
| // When passed to contains | ||
| // Then it should return false | ||
| test.todo("contains on empty object returns false"); | ||
| // test.todo("contains on empty object returns false"); | ||
|
|
||
| test("contains an empty object returns false", () => { | ||
| const obj = {}; | ||
| expect(contains(obj, "a")).toBe(false); | ||
| }); | ||
| // Given an object with properties | ||
| // When passed to contains with an existing property name | ||
| // Then it should return true | ||
| test("contains an object with properties return ture", () => { | ||
| const obj = { a: 1, b: 2, c: 3 }; | ||
| expect(contains(obj, "a")).toBe(true); | ||
| }); | ||
|
|
||
| // Given an object with properties | ||
| // When passed to contains with a non-existent property name | ||
| // Then it should return false | ||
| test("contains an object with propreties return false for non-existing property", () => { | ||
| const obj = { a: 1, b: 2, c: 3 }; | ||
| expect(contains(obj, "d")).toBe(false); | ||
| }); | ||
|
|
||
| // Given invalid parameters like an array | ||
| // When passed to contains | ||
| // Then it should return false or throw an error | ||
| test("contains with invalid parameters return false", () => { | ||
| const obj = ["a", "b", "c", "d"]; | ||
| expect(contains(obj, "a")).toBe(false); | ||
| }); | ||
|
Comment on lines
45
to
+51
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. This test cannot yet confirm that the function correctly returns false when the first argument is an array. Arrays are objects, with their indices acting as keys. A proper test should use a valid Besides array, you should also test other invalid parameters such as |
||
|
|
||
| // or to throw error | ||
| // })) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(countryCurrencyPairs) { | ||
| return Object.fromEntries(countryCurrencyPairs); | ||
| } | ||
|
|
||
| module.exports = createLookup; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,29 @@ | ||
| function parseQueryString(queryString) { | ||
| const queryParams = {}; | ||
| if (queryString.length === 0) { | ||
| return queryParams; | ||
| } | ||
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| if (!queryString) return queryParams; | ||
|
|
||
| const pairs = queryString.split("&"); | ||
|
|
||
| for (const pair of pairs) { | ||
| if (!pair) continue; | ||
|
|
||
| const index = pair.indexOf("="); | ||
|
|
||
| let key, value; | ||
|
|
||
| if (index === -1) { | ||
| key = decodeURIComponent(pair); | ||
| value = true; | ||
| } else { | ||
| key = decodeURIComponent(pair.slice(0, index)); | ||
| value = decodeURIComponent(pair.slice(index + 1)); | ||
| } | ||
|
|
||
| queryParams[key] = value; | ||
| } | ||
|
|
||
| return queryParams; | ||
| } | ||
|
|
||
| module.exports = parseQueryString; | ||
| module.exports = parseQueryString; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| function tally() {} | ||
| function tally(items) { | ||
| if (!Array.isArray(items)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
| const result ={ }; | ||
| for (let item of items){ | ||
| result[item]=(result[item] || 0)+1; | ||
| } | ||
|
Comment on lines
+5
to
+8
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; | ||
Uh oh!
There was an error while loading. Please reload this page.