-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
improve median #869
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
improve median #869
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.
Any iterables can be converted to an array by simply calling Array.from(iterator)
. I believe the previous implementation was more concise and to the point.
If you want a pure function, I would suggest a "rest" argument for the function.
'I believe the previous implementation was more concise and to the point' - no problem === |
Describe your change:
Fix a bug
In the last implementation, finding the median is not a pure function. It mutates the original array.
const arr = [3,2,1]
averageMedian(arr)
numbers = numbers.sort(sortNumbers)
so arr will be [1,2,3].
Why? The function for finding the median should not change arr by sorting
====
Now this fn can work with generators and custom median selector (for example of str lengths)