generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 219
Sheffield | 25-ITP-SEP | Declan Williams | Sprint 2 | Data groups #845
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
CatchingKiyoko
wants to merge
37
commits into
CodeYourFuture:main
from
CatchingKiyoko:Data-Groups-Sprint-2
Closed
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
ca796ca
added comments for my prediction and given suggestion
CatchingKiyoko 87aa2f8
Fix console log to correctly display house number from address object
CatchingKiyoko b586c5d
added comments predicting and expecting to happen and given reasons t…
CatchingKiyoko 3d8c0e4
Fix error by using Object.values() in for...of loop
CatchingKiyoko 0c740e3
Add comments to explain expected behavior and necessary fixes for ing…
CatchingKiyoko 996a55e
refactored code in console log to correctly call ingredients to the c…
CatchingKiyoko cbcab13
Refactor parseQueryString to handle values with "=" by splitting only…
CatchingKiyoko 53b286f
added tests to cover parses keys with multiple "=" signs
CatchingKiyoko 88ad32f
Add test for parsing querystring with no value
CatchingKiyoko 60d9b7c
added comments answering questions around the function invert
CatchingKiyoko 2307da8
Fix implementation of invert function to correctly swap keys and values
CatchingKiyoko ac0ffda
implemented parameters to contains function and to check if obj is an…
CatchingKiyoko 339ddd7
added jest test: for when an empty object is passed into contains fun…
CatchingKiyoko b96968f
Fix type check for object in contains function
CatchingKiyoko 228755f
fix: add missing return false to handle cases where key is not found
CatchingKiyoko 370b07c
implemented: loop through object keys using for...in
CatchingKiyoko 3b15131
added test case for contains function to verify it returns true for e…
CatchingKiyoko b7b0215
refactor: update test descriptions for clarity and consistency and ad…
CatchingKiyoko 8f6fe97
added test case for when invalid parameters like an array
CatchingKiyoko 6742902
initialize results object in createLookup function
CatchingKiyoko c3764f5
implemented parameter to createLookup function and correct result var…
CatchingKiyoko 7525314
fix: correct variable name from 'result' to 'results' in createLookup…
CatchingKiyoko 84e8552
test: implement test for country currency code lookup functionality
CatchingKiyoko a11cbcd
test: add test case for returning an empty object with an empty array
CatchingKiyoko 9539ce3
implement input validation for tally function to ensure array input
CatchingKiyoko a257896
added a empty object to store counted items
CatchingKiyoko 79afe87
implemented jest test for if function(Tally) is given an empty array
CatchingKiyoko 0da94ce
Add for...of loop to count how many times each item appears in array
CatchingKiyoko 2a37e5e
added jest test for when a given array has duplicate items
CatchingKiyoko 430f315
added jest test for a given invalid input
CatchingKiyoko 08460b7
Merge branch 'main' into Data-Groups-Sprint-2
CatchingKiyoko ff5470e
Merge branch 'CodeYourFuture:main' into Data-Groups-Sprint-2
CatchingKiyoko 95558d0
Merge branch 'CodeYourFuture:main' into Data-Groups-Sprint-2
CatchingKiyoko a97163f
Merge branch 'CodeYourFuture:main' into Data-Groups-Sprint-2
CatchingKiyoko 6044533
Fix: update console log to display ingredients on a single line using…
CatchingKiyoko 6f7ef9c
Refactor: improve readability of the contains function by adjusting i…
CatchingKiyoko 4141123
Refactor: change itemCount initialization to use Object.create(null) …
CatchingKiyoko 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,21 @@ | ||
| // Predict and explain first... | ||
| // i expect the code to run but not produce the ingredients as its not calling the key pair values of ingredients array with the recipe.ingredients call | ||
| // i also expect that each part will not be produced on a new line when called as there is no new line breaks called with the \n after each property has been called in the console log | ||
|
|
||
| // This program should log out the title, how many it serves and the ingredients. | ||
| // Each ingredient should be logged on a new line | ||
| // How can you fix it? | ||
| // to fix this you would need to change "${recipe}`" to "${recipe.ingredients}`" | ||
| // to fix each ingredient being called individually you'd use the array call on "recipe.ingredients[]\n" to call individual elements of the array and put them on a new line | ||
|
|
||
| const recipe = { | ||
| title: "bruschetta", | ||
| serves: 2, | ||
| ingredients: ["olive oil", "tomatoes", "salt", "pepper"], | ||
| }; | ||
|
|
||
| console.log(`${recipe.title} serves ${recipe.serves} | ||
| ingredients: | ||
| ${recipe}`); | ||
| console.log( | ||
| `${recipe.title}\n serves ${ | ||
| recipe.serves | ||
| }\n ingredients:\n ${recipe.ingredients.join(", ")}` | ||
| ); |
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,14 @@ | ||
| function contains() {} | ||
| function contains(obj, key) { | ||
| // check if "obj" is an object and not an array and we are working with plain objects | ||
| if (typeof obj !== "object" || obj === null || Array.isArray(obj)) | ||
| return false; | ||
|
|
||
| // loop over each property name in the object | ||
| for (let properties in obj) { | ||
| // check that if each of the properties names matches what were looking for in the key and return true if matches | ||
| if (properties === key) return true; | ||
| } | ||
|
|
||
| return false; // if no object or key is found return false | ||
| } | ||
| 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,14 @@ | ||
| function createLookup() { | ||
| function createLookup(pairs) { | ||
| // implementation here | ||
| const results = {}; // create an empty object to be able to store results | ||
|
|
||
| // loop through each of the pairs in the array | ||
| for (const [country, currency] of pairs){ | ||
| // add new key value pairs to the object "country" is the key and "currency" is the value | ||
| results[country] = currency; | ||
| } | ||
|
|
||
| return results; // returns the final object that maps each key to the corresponding values | ||
| } | ||
|
|
||
| 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,21 @@ | ||
| function tally() {} | ||
| function tally(array) { | ||
| // ensures that the input is an array. | ||
| if (!Array.isArray(array)) { | ||
| // throw an error if input is not an array | ||
| throw new Error("expected input to be an array"); | ||
| } | ||
|
|
||
| // make an empty object to store items counted | ||
| const itemCount = Object.create(null); | ||
|
|
||
| // loop over each item in the array | ||
| for (const item of array) { | ||
| // if the item hasn't been counted yet treat it as 0 | ||
| itemCount[item] = (itemCount[item] || 0) + 1; // then adds 1 to either start or increment the count for this item | ||
| } | ||
|
|
||
| return itemCount; | ||
| } | ||
| console.log(tally(["toString", "toString"])); | ||
|
|
||
| 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
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.
Please note that in real querystring, both
keyandvalueare percent-encoded or URL encoded in the URL. For example, the string "5%" will be encoded as "5%25". So to get the actual value of "5%25" (whether it is a key or value in the querystring), you should call a function to decode it.May I suggest looking up any of these terms, and "How to decode URL encoded string in JS"?
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.
using decodeURIComponent() takes a URL encoded string and converts it back to the original characters so that it can make the key value pairs in a readable manner as they have special characters like "&, = and %" to not break the url format.
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 exercise is good for programming practice.
In practice, we could just use the built-in Class,
URLSearchParams,to parse query strings.