-
-
Notifications
You must be signed in to change notification settings - Fork 191
Glasgow | 25-ITP-SEP | Fare Bakhet | Sprint 2 | Coursework/sprint 2 #885
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
base: main
Are you sure you want to change the base?
Glasgow | 25-ITP-SEP | Fare Bakhet | Sprint 2 | Coursework/sprint 2 #885
Conversation
| ${recipe.ingredients[0]} | ||
| ${recipe.ingredients[1]} | ||
| ${recipe.ingredients[2]} | ||
| ${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.
This approach will only work when there are exactly 4 ingredient.
Can you figure out a solution that could work for any number of ingredients?
| test("given invalid parameters like an array, returns false", function (){ | ||
| const input = [1, 2, 3]; | ||
| const propertyName = 'a'; | ||
| const currentOutput = contains(input, propertyName); | ||
| const targetOutput = false; | ||
|
|
||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); |
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.
Arrays are objects in JavaScript, and they do have property names -- just not the same ones as objects.
Which keys do arrays have, and how does that affect how reliable your test is?
When testing whether the function handles arrays properly, try using a key that an array might
realistically contain. Otherwise, you might get a passing test even if the function isn't checking for arrays at all.
| } | ||
|
|
||
| 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), we 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"?
| throw new Error("tally expects an array"); | ||
| } | ||
|
|
||
| const counts = {}; |
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.
| function countWords(str) { | ||
| const result = {}; | ||
| if (!str || str.trim().length === 0) { | ||
| return result; | ||
| } | ||
| const words = str.split(" "); | ||
| for (const word of words) { | ||
| if (result[word] === undefined) { | ||
| result[word] = 1; | ||
| } else { | ||
| result[word] += 1; | ||
| } | ||
| } | ||
| return result; | ||
| } |
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.
When you you have time to test your implementation, here are some test cases you can use to check your implementation:
countWords("Hello,World! Hello World!");
countWords("constructor constructor");
countWords(" Hello World ");
Learners, PR Template
Self checklist
Changelist
I have completed the tasks.
Questions
No questions.