-
-
Notifications
You must be signed in to change notification settings - Fork 153
London | May-2025 | Halimatou Saddiyaa | Module-Data-Groups | Sprint 1 #548
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?
London | May-2025 | Halimatou Saddiyaa | Module-Data-Groups | Sprint 1 #548
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.
Overall this is really good. Your solutions are correct and all the tests pass. I will mark this as complete. I am leaving some comments which I hope are helpful. I can discuss or expand if you like.
Sprint-1/fix/median.js
Outdated
// Secondly, we need to implement a function that filter out non numeric values. | ||
const numbers = list.filter((item) => typeof item === "number"); | ||
|
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.
Excellent work. However there is an edge case that the tests don't require you to handle. You might want to look at the special NaN
property and consider whether the code would work if this value appeared in one of the test arrays. As I say it is not required but might be something to watch out for in the future.
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.
Thank you, the code might not work with Nan as although it is a number it's not a valid numeric value for math operations.
I've corrected my function to include the case of NaN and added a test to check.
Sprint-1/implement/dedupe.js
Outdated
function dedupe(array) { | ||
const seen = new Set(); | ||
return array.filter((item) => { | ||
if (seen.has(item)) { | ||
return false; | ||
} | ||
seen.add(item); | ||
return true; | ||
}); | ||
} |
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.
Clever solution. Using a Set
is the right approach in most de-duplication problems. However there are easier ways to populate a Set
from an Array
. Do you need to use the filter
function at all?
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.
Thanks, I don't need to use the filter function as I can directly use Set and populate it from an Array. I've corrected my code to reflect that.
function findMax(arr) { | ||
const numbers = arr.filter((item) => typeof item === "number"); | ||
if (numbers.length === 0) { | ||
return -Infinity; | ||
} | ||
return Math.max(...numbers); | ||
} |
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.
Excellent solution.
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.
Thanks
Sprint-1/implement/sum.js
Outdated
function sum(arr) { | ||
return arr.reduce((total, current) => { | ||
if (typeof current === "number") { | ||
return total + current; | ||
} | ||
return total; | ||
}, 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.
This is good. However it would be more typical pattern to use filter
then reduce
rather than having your 'filtering' logic within the reduce
function. Why do you think that pattern would be preferred?
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.
Thanks, I think using filter then reduce will be preferred because it separates the two steps and the code is then easier to read and understand. I've updated my code to reflect that.
Thank you for reviewing my PR @a-robson |
You're welcome. I've looked over your changes and they are all really good. |
Learners, PR Template
Self checklist
Changelist
I've ompleted the following coursework on Sprint 1 of the Module Data Groups:
Please review my PR
Questions
Ask any questions you have for your reviewer.