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

Bug: sort by comparer overrides the default sort #18

Closed
pleek91 opened this issue Feb 12, 2020 · 2 comments
Closed

Bug: sort by comparer overrides the default sort #18

pleek91 opened this issue Feb 12, 2020 · 2 comments
Labels

Comments

@pleek91
Copy link

pleek91 commented Feb 12, 2020

It appears that if you are using sort.by() with an array, custom comparers are not working as expected.

See this minimal test case.

In that example I'm sorting by status and then by title. Status has a custom comparer and title does not. However, you can see in the logs that the status comparer is being called for the title sort as well. It does not fall back to the default once a comparer has been given.

I would expect the test case to output

[
{ status: 0, title: "A" },
{ status: 0, title: "B" },
{ status: 0, title: "D" },
{ status: 1 title: "C" },
]

However it outputs

[
{ status: 0, title: "A" },
{ status: 0, title: "D" },
{ status: 0, title: "B" },
{ status: 1 title: "C" },
]

If I remove the numeric comparer from status, or add the alpha comparer to title, or if I remove the numeric comparer from status and add the alpha comparer to title then it outputs as expected.

@snovakovic
Copy link
Owner

@pleek91 thanks for bringing it up and for very detail test case!

The issue is fixed and should work as expected from 2.1.1 version of fast-sort

@pleek91
Copy link
Author

pleek91 commented Feb 13, 2020

After updating my test case to 2.1.1 it now works as expected. Thank you for such a quick response and turnaround!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants