-
-
Notifications
You must be signed in to change notification settings - Fork 278
Sheffield | 26-ITP-Jan | Mahammad Osman | Sprint 2 | Data Groups #1131
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
Darkidd77
wants to merge
6
commits into
CodeYourFuture:main
Choose a base branch
from
Darkidd77: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
6 commits
Select commit
Hold shift + click to select a range
ab95ae3
Fix syntax errors in address.js, author.js, and recipe.js; update com…
Darkidd77 497e661
Implement contains function and enhance tests for property checks
Darkidd77 dde6065
Implement createLookup function and add corresponding tests for count…
Darkidd77 a31527c
Enhance query string parser and add comprehensive tests for edge case…
Darkidd77 15cf3e1
Implement invert function to swap keys and values in an object; add c…
Darkidd77 0118bc5
Moved CYF-Workshop folder as it dirtied the work tree of git no allow…
Darkidd77 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,5 @@ | ||
| function contains() {} | ||
| function contains(obj, prop) { | ||
| 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,11 @@ | ||
| function createLookup() { | ||
| function createLookup(countryCurrencyPairs) { | ||
| // implementation here | ||
|
|
||
| const lookup = {}; | ||
| for (const [key, value] of countryCurrencyPairs) { | ||
| lookup[key] = value; | ||
| } | ||
| 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
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,19 @@ | ||
| function tally() {} | ||
| function tally(list) { | ||
| if (!Array.isArray(list)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| const counts = {}; | ||
|
|
||
| for (const item of list) { | ||
| if (counts[item]) { | ||
| counts[item] = counts[item] + 1; | ||
| } else { | ||
| counts[item] = 1; | ||
| } | ||
| } | ||
|
Comment on lines
+6
to
+14
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. Does the following function call returns the value you expect? Suggestion: Look up an approach to create an empty object with no inherited properties. |
||
|
|
||
| return counts; | ||
| } | ||
|
|
||
| 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,25 @@ | ||
| const invert = require("./invert"); | ||
|
|
||
| test("invert returns an object with keys and values swapped, simple case", () => { | ||
| const input = { a: 1 }; | ||
| const expectedOutput = { 1: "a" }; | ||
| expect(invert(input)).toEqual(expectedOutput); | ||
| }); | ||
|
|
||
| test("invert returns an object with keys and values swapped, multiple pairs", () => { | ||
| const input = { a: 1, b: 2 }; | ||
| const expectedOutput = { 1: "a", 2: "b" }; | ||
| expect(invert(input)).toEqual(expectedOutput); | ||
| }); | ||
|
|
||
| test("invert handles empty objects", () => { | ||
| const input = {}; | ||
| const expectedOutput = {}; | ||
| expect(invert(input)).toEqual(expectedOutput); | ||
| }); | ||
|
|
||
| test("invert handles non-string values", () => { | ||
| const input = { x: true, y: null }; | ||
| const expectedOutput = { true: "x", null: "y" }; | ||
| expect(invert(input)).toEqual(expectedOutput); | ||
| }); |
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.
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.
This test cannot not yet confirm that the function correctly returns false when the first argument is an array.
This is because
contains([1, 2, 3], "a")could also returnfalsesimply because "a" is not a key of the array.Arrays are objects, with their indices acting as keys. A proper test should use a valid
key to ensure the function returns
falsespecifically because the input is an array, not because the key is missing.In addition, does your function behave as expected when the first argument is
nullorundefined?