London | 26-ITP-May | Vito Moratti | Sprint 1 | Module data groups/sprint1 - #1297
London | 26-ITP-May | Vito Moratti | Sprint 1 | Module data groups/sprint1#1297vmoratti wants to merge 28 commits into
Conversation
| if (!Array.isArray(list) || list.length < 2) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Why can't an array containing one number have a median?
| test("given an array with no duplicates, it returns a copy of the original array", () => { | ||
| expect(dedupe([1, 2, 3])).toEqual([1, 2, 3]); | ||
| }); |
There was a problem hiding this comment.
Your function implementation is correct. However, this test could be improved to better ensure
that any future changes continue to align with the expected behavior described on line 25:
Then it should return a copy of the original array
This test should fail if the function returns the original array (instead of a copy of the original array).
The current test checks only if both the original array and the returned array contain identical elements.
In order to validate the returned array is a different array, we need an additional check.
Can you find out what this additional check is?
There was a problem hiding this comment.
i have now added test to check if the returned array is a copy
| @@ -1,4 +1,10 @@ | |||
| function sum(elements) { | |||
| let innit = 0; | |||
There was a problem hiding this comment.
What does the name innit mean?
There was a problem hiding this comment.
I have changed the variable name to "counter"
| return innit; | ||
| } |
Update median calculation to handle empty arrays.
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good. I just have a few more suggestions.
| if (filteredList.length < 1) { | ||
| return null; | ||
| } | ||
| const sortedList = filteredList.sort((a, b) => a - b); |
There was a problem hiding this comment.
Do explore the difference between .toSorted() and .sort().
| const original = [1, 2, 3]; | ||
| const result = dedupe(original); | ||
|
|
||
| expect(result).toEqual([1, 2, 3]); | ||
| expect(result).not.toBe(original); |
There was a problem hiding this comment.
This test is correct, but shouldn't it be defined at line 27?
| @@ -1,4 +1,13 @@ | |||
| function sum(elements) { | |||
| let counter = 0; | |||
| @@ -1,4 +1,13 @@ | |||
| function sum(elements) { | |||
| let counter = 0; | |||
| const filteredList = elements.filter((value) => typeof value === "number" && !isNaN(value) && isFinite(value)); | |||
There was a problem hiding this comment.
Note: Number.isFinite() checks all three conditions.
Self checklist
Changelist
Completed exercises for Sprint 1 except for stretch, which i didn't have time for.
Questions
Stretch is optional right?