-
-
Notifications
You must be signed in to change notification settings - Fork 149
West Midlands | ITP-MAY25 | Saleh Yousef | Module-Data-Groups | Sprint-2 #622
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
80834dc
878d69e
bef438d
f63be1b
3cb3c9e
9505da4
41e83d6
1fc3cc5
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function createLookup() { | ||
// implementation here | ||
function createLookup(pairs) { | ||
const result = {}; | ||
|
||
for (const [countryCode, currencyCode] of pairs) { | ||
result[countryCode] = currencyCode; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
module.exports = createLookup; |
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. test passed |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,42 @@ test("parses querystring values containing =", () => { | |
"equation": "x=y+1", | ||
}); | ||
}); | ||
|
||
test("parses querystring with multiple values", () => { | ||
expect(parseQueryString("name=John&age=30")).toEqual({ | ||
"name": "John", | ||
"age": "30", | ||
}); | ||
}); | ||
test("parses querystring with multiple values with same key", () => { | ||
expect(parseQueryString("name=John&name=Jane")).toEqual({ | ||
"name": "Jane", // Last value should overwrite previous ones | ||
}); | ||
}); | ||
|
||
test("parses querystring without key", () => { | ||
Comment on lines
+13
to
+26
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. Good edge cases! |
||
expect(parseQueryString("=Python")).toEqual({ | ||
"": "Python", // Empty key should be handled | ||
}); | ||
}); | ||
|
||
test("parses query string with multiple = in value", () => { | ||
const input = "math=2+2=4"; | ||
const expected = { math: "2+2=4" }; | ||
expect(parseQueryString(input)).toEqual(expected); | ||
}); | ||
|
||
test("parses multiple key-value pairs with = in one of the values", () => { | ||
const input = "name=John&equation=x=y+1"; | ||
const expected = { | ||
name: "John", | ||
equation: "x=y+1" | ||
}; | ||
expect(parseQueryString(input)).toEqual(expected); | ||
}); | ||
|
||
test("parses URL encoded query strings correctly", () => { | ||
const input = "name=Saleh%20O&city=New%20York"; | ||
const expected = { name: "Saleh O", city: "New York" }; | ||
expect(parseQueryString(input)).toEqual(expected); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
function tally() {} | ||
function tally(array) { | ||
if (!Array.isArray(array)) { | ||
throw new Error("Input must be an array"); | ||
} | ||
const counts = {}; | ||
|
||
for (const item of array) { | ||
if (item === undefined || item === null || typeof item === "object" || typeof item === "function") { | ||
continue; // Skip invalid or problematic values | ||
} | ||
const key = String(item); // Convert to string to avoid type confusion | ||
counts[key] = (counts[key] || 0) + 1; | ||
} | ||
|
||
return counts; | ||
} | ||
|
||
module.exports = tally; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.