-
-
Notifications
You must be signed in to change notification settings - Fork 160
NW | 25-ITP-Sep | TzeMing Ho | Sprint 1 | sprint-1-exercises #792
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?
Conversation
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.
Looking really good - I've left some more challenging question
I will mark as complete & this is done - but if you can answer these I think it will be a good challenge 🙂
} | ||
|
||
// return [] if arr is [] | ||
if (arr.length === 0) return []; |
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.
Do we need a special case here?
// return [] if arr is [] | ||
if (arr.length === 0) return []; | ||
|
||
return [...new Set(arr)]; |
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.
What's special about Set
that solves our problem here?
test("given an array with no duplicates, it returns the original array", () => { | ||
expect(dedupe(["a", "b", "c"])).toEqual(["a", "b", "c"]); | ||
expect(dedupe([1, 2, 3])).toEqual([1, 2, 3]); | ||
expect(dedupe([{ key1: "a" }, { key2: "b" }, { key3: "c" }])).toEqual([ |
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.
challenge: what would you expect if I did this?
dedupe([{ key1: "a" }, { key1: "a" }, { key1: "a" }])
return 0; | ||
} | ||
|
||
return elements.reduce((acc, num) => acc + num, 0); |
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.
Could you explain what this reduce function is doing?
Learners, PR Template
Self checklist
Changelist
I have created a function for finding the median, both tests and functions in the implement exercise, refactored the loop function, and found out the frequency of time travel.