London | 26-ITP-May | Zadri Abdule | Sprint 2 | Exercises - #1302
London | 26-ITP-May | Zadri Abdule | Sprint 2 | Exercises#1302Zadri415 wants to merge 12 commits into
Conversation
| // When passed to contains | ||
| // Then it should return false or throw an error | ||
| test("contains with invalid parameters returns false", () => { | ||
| expect(contains([], 'a')).toBe(false); |
There was a problem hiding this comment.
contains([], 'a') could also return false simply because "a" is not a key of the array.
In JS, arrays are also objects, with their indices acting as keys. A proper test should use a non-empty array along with a valid key of the array to ensure the function returns false specifically because the input is an array, not because the key is missing.
There was a problem hiding this comment.
Thanks for the feedback. Made the suggested changes.
| // {"1":"a"} | ||
|
|
||
| // b) What is the current return value when invert is called with { a: 1, b: 2 } | ||
| // {"1":"a", "2":"b"} |
There was a problem hiding this comment.
The "current return value" in questions (a), (b), and (d) refer to the return value of the original faulty function.
| } | ||
| } else { | ||
| inverted[v] = key; | ||
| } |
There was a problem hiding this comment.
Note: This rewrite version is doing more than just swapping the keys and values. Change is optional.
Supposedly you could change one line of code to fix the problem.
|
The Changelist content is not quite accurate. |
There was a problem hiding this comment.
This file basically remain unchanged since my previous review. The comments I left on this file still hold.
The most recent commit (30719f0) that says "Update invert.js" only removed an empty line from the file:
Learners, PR Template
Self checklist
Changelist