-
-
Notifications
You must be signed in to change notification settings - Fork 324
London | 26-ITP-May | Vito Moratti | Sprint 2 | Coursework #1364
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
vmoratti
wants to merge
17
commits into
CodeYourFuture:main
Choose a base branch
from
vmoratti:Module-Data-Groups/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
17 commits
Select commit
Hold shift + click to select a range
d4df6a4
fix the problem
vmoratti 9256b7f
debug the code
vmoratti 522cb56
debug, and fix code
vmoratti 5dcae6a
add two tests and implement function acordingly
vmoratti c68ec3e
add more tests
vmoratti bc5e89a
implement createLookup() function
vmoratti 2114a9e
write test
vmoratti 78041d6
write complete function to meet the test requirements
vmoratti 6d8eefd
write complete function to taly
vmoratti fbce304
wrte tests
vmoratti b10547d
fix function, write tests
vmoratti 2dbe395
Fix author iteration by using Object.entries
vmoratti 91bfc23
Update property check to use hasOwnProperty
vmoratti aa5ee68
Update test case to check for array's indices
vmoratti 4349ed1
Modify contains function to handle arrays
vmoratti aff50e0
Fix loop index variable in tally function
vmoratti 9ca3f78
Improve contains function property check
vmoratti 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
Some comments aren't visible on the classic Files Changed page.
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,7 @@ | ||
| function contains() {} | ||
|
|
||
| module.exports = contains; | ||
| function contains(obj, prop) { | ||
| const notArray = !Array.isArray(obj); | ||
| if (obj === null || Array.isArray(obj) || obj === Number || obj === undefined) { | ||
| return false; | ||
| } | ||
| return obj.hasOwnProperty(prop); | ||
| } | ||
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,6 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(entries) { | ||
| let obj = Object.fromEntries(entries); | ||
| return obj; | ||
| } | ||
|
|
||
| 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
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(arr) { | ||
| let countOfItemsObj = {}; | ||
| if (!Array.isArray(arr)) { | ||
| throw new Error("Invalid input"); | ||
| } else if (arr.length < 1) { | ||
| return countOfItemsObj; | ||
| } else { | ||
| for (let index = 0; index < arr.length; index++) { | ||
| const exist = Object.hasOwn(countOfItemsObj, arr [index]); | ||
| if (!exist) { | ||
| countOfItemsObj[arr[index]] = 1; | ||
| } else { | ||
| countOfItemsObj[arr[index]] = countOfItemsObj[arr[index]] + 1; | ||
| } | ||
| } | ||
| } | ||
| return countOfItemsObj; | ||
| } | ||
| 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
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.
There are a few more non-object types that should also be rejected. Why not just reject any value that is an array or not an object?
Notes:
obj === Numberis not the correct syntax to check ifobjis a number or not.