Repository navigation
Manchester | 26-ITP-Sep | Rahana Suleiman | Sprint 2 | Sprint2-exercises (Module-Data-Groups) #1509
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
rahanasuleiman8-ship-it
wants to merge
18
commits into
CodeYourFuture:main
Choose a base branch
from
rahanasuleiman8-ship-it:sprint-2
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
18 commits
Select commit
Hold shift + click to select a range
e03a197
Fix address logging to correctly access houseNumber property
rahanasuleiman8-ship-it fda2a31
Fix iteration over author object by using Object.values()
rahanasuleiman8-ship-it ec94c1a
Fix recipe logging to display ingredients correctly
rahanasuleiman8-ship-it 6790d63
Implement contains function to check for property existence in an object
rahanasuleiman8-ship-it c2274c3
Add test case for contains function to check empty object
rahanasuleiman8-ship-it 29ed1ba
Refactor contains test cases for clarity and organization
rahanasuleiman8-ship-it dac152e
Enhance contains tests to cover error handling for non-object inputs
rahanasuleiman8-ship-it 3bc204d
Implement createLookup function to map country codes to currency codes
rahanasuleiman8-ship-it 9fc3877
Fix createLookup function definition by adding parameters and removin…
rahanasuleiman8-ship-it e1ba994
Refactor createLookup tests to remove todo and enhance structure
rahanasuleiman8-ship-it bfb3305
Refactor parseQueryString function to improve handling of query param…
rahanasuleiman8-ship-it 3ec5d4e
Implement tally function to count occurrences of items in an array an…
rahanasuleiman8-ship-it 7bbffaf
Refactor tally tests to enhance structure and remove todo comments
rahanasuleiman8-ship-it 6bd8b6a
Fix invert function to correctly swap keys and values in the object
rahanasuleiman8-ship-it 993aac0
Add tests for invert function to verify key-value swapping and empty …
rahanasuleiman8-ship-it 39f93e7
Refactor contains function to use Object.hasOwn for property checking
rahanasuleiman8-ship-it 96656f5
Refactor parseQueryString function to simplify empty string check and…
rahanasuleiman8-ship-it 6098be3
Refactor contains tests for improved readability and consistency
rahanasuleiman8-ship-it 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,11 @@ | ||
| function contains() {} | ||
| function contains(obj, propertyName) { | ||
| // Check if obj is null, not an object type, or is an array | ||
| if (obj === null || typeof obj !== "object" || Array.isArray(obj)) { | ||
| throw new Error("contains requires an object"); | ||
| } | ||
|
|
||
| // Check if the object has the specified property key | ||
| return Object.hasOwn(obj, propertyName); | ||
| } | ||
|
|
||
| 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,15 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| } | ||
|
|
||
|
|
||
| function createLookup(pairs) { | ||
| // implementation here | ||
| const lookup = {}; | ||
|
|
||
| for (const [countryCode, currencyCode] of pairs) { | ||
| lookup[countryCode] = currencyCode; | ||
| } | ||
|
|
||
| return lookup; | ||
| } | ||
|
|
||
|
|
||
| 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,50 @@ | ||
| function parseQueryString(queryString) { | ||
| const queryParams = {}; | ||
| if (queryString.length === 0) { | ||
| if (!queryString) { | ||
| return queryParams; | ||
| } | ||
|
|
||
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| queryParams[key] = value; | ||
| if (!pair) continue; // Ignore empty pairs | ||
|
|
||
| const index = pair.indexOf("="); | ||
| let rawKey, rawValue; | ||
|
|
||
| if (index === -1) { | ||
| rawKey = pair; | ||
| rawValue = ""; | ||
| } else { | ||
| rawKey = pair.slice(0, index); | ||
| rawValue = pair.slice(index + 1); | ||
| } | ||
|
|
||
| // Helper to decode URI components and replace '+' with spaces | ||
| const decode = (str) => { | ||
| try { | ||
| return decodeURIComponent(str.replace(/\+/g, " ")); | ||
| } catch (e) { | ||
| return str.replace(/\+/g, " "); | ||
| } | ||
| }; | ||
|
|
||
| const key = decode(rawKey); | ||
| const value = decode(rawValue); | ||
|
|
||
| // Handle duplicate keys by storing multiple values in an array | ||
| if (Object.hasOwn(queryParams, key)) { | ||
| if (Array.isArray(queryParams[key])) { | ||
| queryParams[key].push(value); | ||
| } else { | ||
| queryParams[key] = [queryParams[key], value]; | ||
| } | ||
| } else { | ||
| queryParams[key] = value; | ||
| } | ||
| } | ||
|
|
||
| return queryParams; | ||
| } | ||
|
|
||
| module.exports = parseQueryString; | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,24 @@ | ||
| function tally() {} | ||
| // function tally() {} | ||
|
|
||
| // module.exports = tally; | ||
|
|
||
| function tally(arr) { | ||
| // Check if arr is not an array (handling strings, numbers, null, undefined, or objects) | ||
| if (!Array.isArray(arr)) { | ||
| throw new Error("tally requires an array"); | ||
| } | ||
|
|
||
| const result = {}; | ||
|
|
||
| for (const item of arr) { | ||
| if (Object.prototype.hasOwnProperty.call(result, item)) { | ||
| result[item] += 1; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| 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,12 @@ | ||
| const invert = require("./invert.js"); | ||
|
|
||
| describe("invert()", () => { | ||
| test("swaps the keys and values in an object", () => { | ||
| expect(invert({ x: 10, y: 20 })).toEqual({ "10": "x", "20": "y" }); | ||
| expect(invert({ a: 1, b: 2 })).toEqual({ "1": "a", "2": "b" }); | ||
| }); | ||
|
|
||
| test("returns an empty object when passed an empty object", () => { | ||
| expect(invert({})).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.
For more context about last line not terminating with a newline character, please refer to Why GitHub PRs Show That Red Circle: Understanding Newlines at End of Files.