London | 26-ITP-Jan | Miriam Jorna | Sprint 2 | Data Groups#1190
London | 26-ITP-Jan | Miriam Jorna | Sprint 2 | Data Groups#1190miriamjorna wants to merge 5 commits intoCodeYourFuture:mainfrom
Conversation
| // Given invalid parameters like an array | ||
| // When passed to contains | ||
| // Then it should return false or throw an error | ||
| test("given invalid parameters like an array, returns false", () => { | ||
| expect(contains([1, 2, 3], "a")).toEqual(false); | ||
| }); |
There was a problem hiding this comment.
Your function is correct, but we should prepare tests not only to verify our current implementation, but also to ensure that future changes do not alter the function's expected behavior.
This test cannot yet confirm that the function correctly returns false when the first argument is an array.
This is because contains([1, 2, 3], "a") could also return false simply because "a" is not a key of the array.
Arrays are objects, with their indices acting as keys. A proper test should use a valid key to ensure the function returns false specifically because the input is an array, not because the key is missing.
| const index = pair.indexOf("="); | ||
| const key = pair.slice(0, index); | ||
| const value = pair.slice(index + 1); |
There was a problem hiding this comment.
For each of the following function calls, does your function return the value you expect?
Note: These arguments are valid query strings.
parseQueryString("key1=value1&=&key2=value2")
parseQueryString("key=")
parseQueryString("key1=value1&key2")
parseQueryString("=value")
parseQueryString("key1=value1&&key2=value2")| const result = {}; | ||
| for (const item of arr) { | ||
| if (result[item]) { | ||
| result[item]++; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| } |
There was a problem hiding this comment.
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, or
- use
Object.hasOwn()to check ifresultcontains a specific key/item
Self checklist
Changelist
Coursework for Sprint 2.
My mojo went MIA but I've found it back!