Repository navigation
London | 26-ITP-Sep | Hanna Bohlin | Sprint 2 | Sprint 2 exercises #1547
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
habohlin
wants to merge
29
commits into
CodeYourFuture:main
Choose a base branch
from
habohlin:Sprint-2-Coursework
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
29 commits
Select commit
Hold shift + click to select a range
77c1b95
Predicted, explained and debugged address.js
habohlin 78971a1
Predict, explain and debug author.js
habohlin 5a168c1
Predicted, explained and debugged and tidied recipe.js
habohlin 8ab5968
Implemented and tested basic functionality of contains
habohlin 930173f
Added test for passing empty object returning false, it passes already
habohlin 9863145
Add tests and implementation for contains being passed non object. It…
habohlin c22a44a
Implemented basic functionality and test for createLookup
habohlin 37cacd4
Throws when the passed array doesn't contain arrays
habohlin 188a777
THrows when passed nothing
habohlin 9eee54d
Throws when passed nothing or a string
habohlin c1fc819
Implement and test basic functionality of tally.js
habohlin 83440be
Added passing test for when tall is called with empty array
habohlin b0e1da6
Added test for invalid inputs, and implemented function to throw error
habohlin 86d9444
Implemented change to parse values containing =
habohlin 918eeb1
Implemented change to make function ignore empty key-value pairs
habohlin f8faa34
Implemented change so empty string is accepted as key or value
habohlin e5835dd
Implemented URI decoding to decode percent-encoded characters
habohlin 8c5b5a1
Implemented change so + becomes a space
habohlin 8626c0a
Implemented error thrown when passed non-string, and added tests
habohlin 7c6bcab
Tidied up the files, removed function call and formatted with prettier
habohlin 0ee560e
Answered questions, implemented fix of invert and wrote test to prove…
habohlin 9312fb5
Formatted all files with prettier
habohlin ac8fa3b
Formatted all files with prettier
habohlin a911531
Deleted unwanted files
habohlin 3063017
Moved the URI decoding to after splitting on &, to avoid splitting on…
habohlin 8e766e7
Generalised throwing errors for when codes is not an array of arrays
habohlin 029577e
Change replace to replaceAll, to replace all + with a space
habohlin c4dd46f
Added check for if obj was boolean, then it will throw
habohlin dc88da9
Format with prettier
habohlin 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,15 @@ | ||
| function contains() {} | ||
| function contains(obj, property) { | ||
| if ( | ||
| Array.isArray(obj) || | ||
| typeof obj === "string" || | ||
| typeof obj === "number" || | ||
| typeof obj === "boolean" || | ||
| !obj | ||
|
Comment on lines
+2
to
+7
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. What does To "like" or "dislike" this comment, please follow this link |
||
| ) { | ||
| throw new Error("contains requires an object"); | ||
| } | ||
|
|
||
| return property in obj; | ||
| } | ||
|
|
||
| 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,19 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(codes) { | ||
| if ( | ||
| !codes || | ||
| !Array.isArray(codes) || | ||
| !codes.every((currArr) => Array.isArray(currArr)) | ||
| ) { | ||
| throw new Error("createLookup needs an array of arrays"); | ||
| } | ||
|
|
||
| const lookup = {}; | ||
|
|
||
| for (const country of codes) { | ||
| lookup[country[0]] = country[1]; | ||
| } | ||
|
|
||
| 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(items) { | ||
| if (!Array.isArray(items)) { | ||
| throw new Error("tally requires an array"); | ||
| } | ||
|
|
||
| const tallyObj = {}; | ||
|
|
||
| for (const item of items) { | ||
| if (!(item in tallyObj)) { | ||
| tallyObj[item] = 1; | ||
| } else { | ||
| tallyObj[item]++; | ||
| } | ||
| } | ||
|
|
||
| return tallyObj; | ||
| } | ||
|
|
||
| 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,14 @@ | ||
| const invert = require("./invert.js"); | ||
|
|
||
| it("should invert one key-value pair properly", () => { | ||
| expect(invert({ a: 1 })).toEqual({ 1: "a" }); | ||
| }); | ||
|
|
||
| it("should invert several key-value pairs properly", () => { | ||
| expect(invert({ a: 1, b: 2 })).toEqual({ 1: "a", 2: "b" }); | ||
| expect(invert({ x: 10, y: 20, z: 25 })).toEqual({ | ||
| 10: "x", | ||
| 20: "y", | ||
| 25: "z", | ||
| }); | ||
| }); |
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.
How does
address[0]behave differently from trying to iterate overaddress?To "like" or "dislike" this comment, please follow this link