-
-
Notifications
You must be signed in to change notification settings - Fork 320
Birmingham | 26-ITP-May | Toluwalase Tiamiyu | Sprint 2 | Coursework #1317
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
Open
TTiamiyu
wants to merge
13
commits into
CodeYourFuture:main
Choose a base branch
from
TTiamiyu:data-groups-sprint2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
62fe3e1
Fix address logging to correctly display house number
TTiamiyu f92f622
Clarify prediction explanation in address.js comments
TTiamiyu b6eb718
Fix TypeError in author.js by using Object.values() to iterate over o…
TTiamiyu 391bd80
Fix recipe logging to display ingredients correctly
TTiamiyu dd5a43c
Refactor contains tests to include cases for empty objects and invali…
TTiamiyu c7406b2
Implement contains function to check for object properties
TTiamiyu 1014ae0
Add tests for createLookup function to validate country-currency mapp…
TTiamiyu 655bb31
Implement createLookup function to validate input and return an objec…
TTiamiyu 63973cd
Refactor parseQueryString function to handle empty inputs, decode par…
TTiamiyu 1874dec
Refactor tally tests to implement missing test case for empty array a…
TTiamiyu 1c17fbf
Implement tally function to count occurrences of items in an array an…
TTiamiyu 75ce6cb
Fix invert function to correctly swap keys and values, add input vali…
TTiamiyu 01e11ec
Add tests for invert function to validate key-value swapping and hand…
TTiamiyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| function contains() {} | ||
| function contains() { | ||
| if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { | ||
| return false; | ||
| } | ||
| return Object.prototype.hasOwnProperty.call(obj, prop); | ||
| } | ||
|
|
||
| module.exports = contains; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| if (!Array.isArray(countryCurrencyPairs)) { | ||
| return {}; | ||
| } | ||
| return Object.fromEntries(countryCurrencyPairs); | ||
| } | ||
|
|
||
| module.exports = createLookup; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,65 @@ | ||
| function parseQueryString(queryString) { | ||
| const queryParams = {}; | ||
| if (queryString.length === 0) { | ||
| return queryParams; | ||
| const result = {}; | ||
|
|
||
| // Return empty object for empty or non-string inputs | ||
| if (typeof queryString !== "string" || !queryString.trim()) { | ||
| return result; | ||
| } | ||
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| queryParams[key] = value; | ||
| // Optional: strip leading '?' if passed a full URL search string (e.g., "?a=1") | ||
| const sanitizedInput = queryString.startsWith("?") | ||
| ? queryString.slice(1) | ||
| : queryString; | ||
|
|
||
| // Split pairs by '&' | ||
| const pairs = sanitizedInput.split("&"); | ||
|
|
||
| for (const pair of pairs) { | ||
| // Ignore empty pairs (e.g. from consecutive '&&' or trailing '&') | ||
| if (!pair) continue; | ||
|
|
||
| // Find the FIRST '=' to separate key and value correctly | ||
| const equalIndex = pair.indexOf("="); | ||
|
|
||
| let rawKey = ""; | ||
| let rawValue = ""; | ||
|
|
||
| if (equalIndex === -1) { | ||
| // Key with no '=' (e.g., "key" -> key="key", value="") | ||
| rawKey = pair; | ||
| rawValue = ""; | ||
| } else { | ||
| // Split strictly on the first '=' so values containing '=' stay intact | ||
| rawKey = pair.slice(0, equalIndex); | ||
| rawValue = pair.slice(equalIndex + 1); | ||
| } | ||
|
|
||
| // Helper to decode query string encoding (+ to space, percent-encoding) | ||
| const decodeParam = (str) => { | ||
| try { | ||
| return decodeURIComponent(str.replace(/\+/g, " ")); | ||
| } catch { | ||
| // Fallback if URI decoding fails on malformed input | ||
| return str.replace(/\+/g, " "); | ||
| } | ||
| }; | ||
|
|
||
| const key = decodeParam(rawKey); | ||
| const value = decodeParam(rawValue); | ||
|
|
||
| // Handle single key vs duplicate keys | ||
| if (Object.prototype.hasOwnProperty.call(result, key)) { | ||
| if (Array.isArray(result[key])) { | ||
| result[key].push(value); | ||
| } else { | ||
| result[key] = [result[key], value]; | ||
| } | ||
| } else { | ||
| result[key] = value; | ||
| } | ||
| } | ||
|
|
||
| return queryParams; | ||
| return result; | ||
| } | ||
|
|
||
| module.exports = parseQueryString; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| function tally() {} | ||
| function tally() { | ||
| if (!Array.isArray(items)) { | ||
| throw new TypeError("Input must be an array"); | ||
| } | ||
| return items.reduce((acc, item) => { | ||
| // Increment count if key exists, otherwise initialize to 1 | ||
| acc[item] = (acc[item] || 0) + 1; | ||
| return acc; | ||
| }, {}); | ||
| } | ||
|
|
||
| module.exports = tally; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| const invert = require("./invert.js"); | ||
|
|
||
| describe("invert()", () => { | ||
| test("swaps keys and values for a single key-value pair", () => { | ||
| expect(invert({ a: 1 })).toEqual({ 1: "a" }); | ||
| }); | ||
|
|
||
| test("swaps keys and values for multiple key-value pairs", () => { | ||
| expect(invert({ x: 10, y: 20 })).toEqual({ 10: "x", 20: "y" }); | ||
| expect(invert({ a: "1", b: "2" })).toEqual({ 1: "a", 2: "b" }); | ||
| }); | ||
|
|
||
| test("handles empty objects", () => { | ||
| expect(invert({})).toEqual({}); | ||
| }); | ||
|
|
||
| test("handles non-object invalid inputs gracefully", () => { | ||
| expect(invert(null)).toEqual({}); | ||
| expect(invert(["a", "b"])).toEqual({}); | ||
| expect(invert("string")).toEqual({}); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 tried running the tests? Is there anything missing?