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
Are there plans to implement a guaranteed-stable sorting method? #59
Comments
More info on V8's unstable sort here: |
I'll do some research and see what the cost would be, that will help me figure out how to handle it. Worst case there can at least be a build option for it. |
For what it's worth, here's how I implemented stable sorting: In the beginning of _.sortBy, when it's mapping the list of values onto criteria&value objects, I also add the index as a property:
And I created a modified
|
Awesome! I will patch this. It might slip into the 0.5.0 release. |
Wait, what if both criteria are undefined? |
@ricklerre Good call. I'll patch that up. |
patched here. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I have a case where I'm using _.sortBy to order an array of objects by an optional "order" property that is almost always undefined.
These objects are then rendered in a list visible to the user, so using an unstable sort algorithm (like in V8) confuses the user by causing items to jump up and down the list seemingly for no reason.
I've solved my problem with my own stable sort function based on a modified implementation of _.sortBy. However, I'm wondering if you plan to add built-in support for "forcing" the sort to be stable, perhaps with an optional argument?
Thanks!
The text was updated successfully, but these errors were encountered: