-
-
Notifications
You must be signed in to change notification settings - Fork 283
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
08e0087
74e551f
beabd1b
475ab41
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.
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. as you said I can use either I kept the key in object in the function implemented already |
||
|
|
||
| module.exports = contains; | ||
| 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,19 @@ | ||
| function tally() {} | ||
| function tally(items) { | ||
| if (!Array.isArray(items)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| const result = {}; | ||
|
|
||
| for (let item of items) { | ||
| if (Object.hasOwn(result, item)) { | ||
| result[item] += 1; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| module.exports = tally; |
Uh oh!
There was an error while loading. Please reload this page.