-
-
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
Sheffield | 25-ITP-SEP | Declan Williams | Sprint 2 | Data groups #845
Conversation
…onsole on new lines
… the first occurrence and rejoining the rest
… object and not an array
and check for matching key inside loop and return true if matches during iteration
…xisting properties
…ded test for non existent properties
Sprint-2/debug/recipe.js
Outdated
| console.log(`${recipe.title} serves ${recipe.serves} | ||
| ingredients: | ||
| ${recipe}`); | ||
| console.log(`${recipe.title}\n serves ${recipe.serves}\n ingredients:\n ${recipe.ingredients[0]}\n ${recipe.ingredients[1]}\n ${recipe.ingredients[2]}\n ${recipe.ingredients[3]}`); |
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.
Can you improve this statement by using Array.prototype.join() so that the code works for any number of ingredients?
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.
have implemented the change so this is cleaner and scales automatically no matter how many ingredients the array has.
Sprint-2/implement/contains.js
Outdated
| 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" || Array.isArray(obj)) return false; |
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.
type of null is "object" too.
Sprint-2/implement/contains.js
Outdated
| 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; | ||
| } |
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.
Can also consider using Object.hasOwn().
| // rejoin the rest incase there are "=" in the value | ||
| const value = rest.join("="); | ||
|
|
||
| queryParams[key] = value; |
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 key and value are 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.
Sprint-2/implement/tally.js
Outdated
| } | ||
|
|
||
| // make an empty object to store items counted | ||
| const itemCount = {}; |
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.
Does the following function call returns the value you expect?
tally(["toString", "toString"]);
Suggestion: Look up an approach to create an empty object with no inherited properties.
… .join() instead of calling individually to work with any amount of ingredients
…ndentation and formatting and handles null safety
…for a cleaner object creation
cjyuan
left a comment
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.
All good. Keep up the good work.
| // rejoin the rest incase there are "=" in the value | ||
| const value = rest.join("="); | ||
|
|
||
| queryParams[key] = value; |
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.
Learners, PR Template
Self checklist
Changelist