Skip to content
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

Fixing issue with sorting which fails when different datatypes are given... #1880

Closed
wants to merge 2 commits into from

Conversation

eraser88
Copy link

... in the sortby list.

Fixing sorting issue mentioned below :

If i have objects like these :
[{"1", 100}, {"1", 1}, {"1", 2}, {"1", 200}]
If i sort the elements using both the columns then the result should be :
[{"1", 1}, {"1", 2}, {"1", 100}, {"1", 200}]
But in the current code the result that is displayed is :
[{"1", 1}, {"1", 100}, {"1", 2}, {"1", 200}]

@@ -347,6 +347,10 @@
var a = left.criteria;
var b = right.criteria;
if (a !== b) {
for (var index = 0; index < _.keys(a).length; index++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will call _.keys(a) on each iteration, you would want to cache this.

@megawac
Copy link
Collaborator

megawac commented Oct 22, 2014

You may want to take a look at a relevant open pr, #1751 and issue #1768

This directly clashes with #1751

@jgonggrijp
Copy link
Collaborator

_.sortBy is for when you can reduce your values to a single string or number so that you can meaningfully apply the < operator. If you need to do something more fancy, pass your own custom comparator function to Array.prototype.sort instead. Note that this function is also available in Underscore OOP notation and in chains as _(yourArray).sort.

Related to #2848.

@jgonggrijp jgonggrijp closed this May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants