-
Notifications
You must be signed in to change notification settings - Fork 268
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
Allow 2-arity Array.sort-style comparators to be passed into sortBy functions #65
Comments
+1 for 2-arity sort support (no preference for new method or overloaded). Currently I go through a |
Haha, I'm going to implement this just so that @Bartvds doesn't do that anymore! ;) |
OK, this is implemented and will be in 0.3.3. |
I apologize @suprememoocow for sort of jumping the gun. Re-reading your original message I see you were (maybe?) interested in doing the implementation yourself. Well, feel free to tweak if you see any issues w/ my version! (Past 3 commits or so covers it.) I definitely love contributions and would like more, so I'll try to be more receptive in the future to someone expressing interest in submitting a PR. |
wow @dtao, so quick 👍 |
Relying on |
@jdalton I'm aware of (at least some of) the issues w/ using The obvious alternative I can think of would be to make a separate method, e.g. |
It can be handled with an options argument as well (more explicit).
We don't handle comparison functions with two arguments. I believe it was originally based on Ruby's sort_by |
Wow, that was a super quick response! @dtao, no problem - I haven't implemented anything yet. Was just being a considerate githubber :) Sounds like using a |
Yeah, I'm also considering maybe just going with |
👍 for |
|
Hi, firstly thanks for such a great library. I really love it.
I would like to provide
Array.sort
-style 2-arity comparator functions to sortBy functions as this method of comparing elements allows the greatest amount of flexibility (for example, reverse sorting of string elements, sorting of different types elements in the same array, or multi-level sorting)By 2-arity comparator functions, I mean ones which take 2 arguments and allow the implementation to return 0, -1 or +1 depending on the order, for example:
Backbone and some other libraries check the length of the comparator function in order to decide whether to use simple 1-arity function or comparator-style 2-arity function.
Let me know what you think: I'm happy to have a crack at doing the work via a pull-request, but would like your feedback on the implementation first.
The text was updated successfully, but these errors were encountered: