London | 26-ITP-May | Alex Jamshidi | Sprint 1 | Exercises #1225
London | 26-ITP-May | Alex Jamshidi | Sprint 1 | Exercises #1225Alex-Jamshidi wants to merge 9 commits into
Conversation
illicitonion
left a comment
There was a problem hiding this comment.
LGTM, a few things to look at
| { input: ["hello", "a", "b", "c"], expected: ["hello", "a", "b", "c"] }, | ||
| { input: [1, 2, "hello", 4, "a", 6], expected: [1, 2, "hello", 4, "a", 6] }, | ||
| ].forEach(({ input, expected }) => | ||
| it(`returns the median for [${input}]`, () => expect(dedupe(input)).toEqual(expected)) |
There was a problem hiding this comment.
This doesn't test one of the parts of the wording of the comment above, that it returns a copy of the original array. How could you test that the array returned is a copy, rather than the same array that was passed in?
There was a problem hiding this comment.
I fixed this with this addition to the test:
it(`returns a non-identical array (copy) for [${input}]`, () =>
expect(dedupe(input)).not.toBe(input));
Where the input of the test is being passed to the dedupe function and the return of that is compared with the original input and checked 'not.toBe' the same
tests pass
| function findMax(list) { | ||
| const numbers = list.filter((n) => Number.isFinite(n)); | ||
| if (numbers.length == 0) { | ||
| return "-Infinity"; |
There was a problem hiding this comment.
You always want to return a number here not a string. Infinity is a special numeric literal in JavaScript - it's a number like others (but a bit special).
| return "-Infinity"; | |
| return -Infinity; |
If you put the term in quotes, you're returning a string, not a number.
|
|
||
| it("empty array returns -Infinity", () => { | ||
| const list = []; | ||
| expect(findMax(list)).toEqual("-Infinity"); |
There was a problem hiding this comment.
| expect(findMax(list)).toEqual("-Infinity"); | |
| expect(findMax(list)).toEqual(-Infinity); |
|
|
||
| it("array with only non-number values, return the least surprising value given how it behaves for all other inputs", () => { | ||
| const list = ["a", "b", "c"]; | ||
| expect(findMax(list)).toEqual("-Infinity"); |
There was a problem hiding this comment.
| expect(findMax(list)).toEqual("-Infinity"); | |
| expect(findMax(list)).toEqual(-Infinity); |
Learners, PR Template
Self checklist
Changelist
Sprint-1 exercises completed