-
-
Notifications
You must be signed in to change notification settings - Fork 197
West Midlands | ITP-Sept-2025 | Hadi Vahidi | Sprint 2 | Module Data Groups #914
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
d1e2c74
9651da6
22655f0
9f0d9c4
f6f580c
8a4b703
5c3214a
122b561
fad683b
9feaf69
b793f4b
08af2c8
2b7ed5b
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,9 @@ | ||
| function contains() {} | ||
| function contains(obj, key) { | ||
| if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { | ||
| return false; | ||
| } | ||
|
|
||
| return Object.prototype.hasOwnProperty.call(obj, key); | ||
| } | ||
|
|
||
| module.exports = contains; |
|
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. Can this script even run? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(pairs) { | ||
| const lookup = {}; | ||
|
|
||
| for (let i = 0; i < pairs.length; i++) { | ||
| const pair = pairs[i]; | ||
| const country = pair[0]; | ||
| const currency = pair[1]; | ||
| lookup[country] = currency; | ||
| } | ||
|
|
||
| return lookup; | ||
| } | ||
|
|
||
| module.exports = createLookup; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,25 @@ | ||
| function parseQueryString(queryString) { | ||
| const queryParams = {}; | ||
| if (queryString.length === 0) { | ||
| if (!queryString) { | ||
| return queryParams; | ||
| } | ||
|
|
||
| function decodePart(text) { | ||
| try { | ||
| return decodeURIComponent(text); | ||
| } catch (error) { | ||
| return text; | ||
| } | ||
| } | ||
|
|
||
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| const index = pair.indexOf("="); // find the first = | ||
| if (index === -1) continue; // skip if no = | ||
|
|
||
| const key = decodePart(pair.substring(0, index)); // before the = | ||
| const value = decodePart(pair.substring(index + 1)); // after the = | ||
| 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. In real query string, both
Can your function handle URL-encoded query string? Suggestion: Look up "How to decode a URL-encoded string in JavaScript". |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,22 @@ | ||
| function tally() {} | ||
| function tally(arr) { | ||
| if (!Array.isArray(arr)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| const counts = Object.create(null); | ||
|
|
||
| for (let i = 0; i < arr.length; i++) { | ||
| const item = arr[i]; | ||
|
|
||
|
|
||
| if (Object.prototype.hasOwnProperty.call(counts, item)) { | ||
| counts[item] += 1; | ||
| } else { | ||
| counts[item] = 1; | ||
| } | ||
| } | ||
|
|
||
| return counts; | ||
| } | ||
|
|
||
| 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.
Have you run this script to test your function implementation?