generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 220
London | 25-ITP-SEP | Imran Mohamed | Sprint 2 | Sprint-2 exercises #809
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d6b4ea3
completed tasks set out in debug folder
i786m 3007268
implement tests and code for contains function
i786m b219369
implement tests and code for lookup
i786m 5a3a247
added querystring tests
i786m 2556038
implement tally function and corresponding tests for various cases
i786m da1b806
refactor parseQueryString to handle multiple equal signs in query par…
i786m 7943541
correct invert implementation to swap keys and values; add tests for …
i786m df2c83e
fix logging of ingredients in recipe; ensure each ingredient is displ…
i786m 1cef373
refactor createLookup function to use destructuring for country and c…
i786m 34a461a
refactor parseQueryString to decode query string before processing; i…
i786m eabafb7
refactor tally function to handle null and undefined values as separa…
i786m 85e40ac
refactor createLookup function to simplify currency handling logic; i…
i786m 359063e
refactor parseQueryString to improve handling of empty query strings …
i786m f8f1af0
Merge branch 'sprint-2' of https://github.com/i786m/Module-Data-Group…
i786m 8d627ff
refactor tally function to improve key generation for different data …
i786m 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,12 @@ | ||
| function contains() {} | ||
| function contains(obj, prop) { | ||
| if(arguments.length !== 2){ | ||
| throw new Error('Invalid input: function requires two arguments'); | ||
| } | ||
| if (obj === null || typeof obj !== 'object' || Array.isArray(obj)) { | ||
| throw new Error('Invalid input: first argument must be an object'); | ||
| } | ||
| return obj.hasOwnProperty(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,29 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(arr) { | ||
| if(!arguments.length) { | ||
| throw new Error('No arguments provided'); | ||
| } | ||
| const result = {}; | ||
| if (!Array.isArray(arr)) { | ||
| return result; | ||
| } | ||
| for (const item of arr) { | ||
| if (Array.isArray(item) && item.length >= 2) { | ||
|
|
||
| const [country, currency] = item; | ||
|
|
||
| if (currency === null || currency === undefined) { | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
| if (((Array.isArray(currency) && currency.length)|| (typeof currency === 'string' && currency.length)) | ||
| && typeof country === "string" && country.length) { | ||
| result[country] = result[country] ? [result[country], currency] : currency; | ||
| } | ||
|
|
||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| module.exports = createLookup; | ||
| 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
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.
Suppose before line 19,
countryis "A"result[country]is"A1"currencyis["A2", "A3"]What is your expected value of
result[country]after line 22?