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

sortBy doesn't perform a stable sort #4926

Closed
goldylucks opened this issue Sep 12, 2020 · 4 comments
Closed

sortBy doesn't perform a stable sort #4926

goldylucks opened this issue Sep 12, 2020 · 4 comments
Labels

Comments

@goldylucks
Copy link

After reading the docs:

This method performs a stable sort, that is, it preserves the original sort order of equal elements.

I implemented two sorts one after the other:

  chats = sortBy(chats, c => -last(c.messages).createdAt)
  chats = sortBy(chats, c => !c.isPinned)

Each one of them works on it's own, but mixing them will cause the second one to mess the first one.

Am I missing something here?

Thanks for the great project btw 🚀

@RillingDev
Copy link

Hi!
Could you explain further what you mean by "mixing them" and "mess the first one"?

@goldylucks
Copy link
Author

I mean if I use both of them in the order posted above, I expect chats to be sorted by isPinned and then by createdAt, but instead it's only sorted by the last sort, isPinned

Is that clearer?

Thanks!

@papb
Copy link

papb commented Oct 1, 2020

@goldylucks Can you provide a MCVE?

@goldylucks
Copy link
Author

I made a sandbox but it works fine, so the problem is probably on my end, so I'm closing this :)

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

No branches or pull requests

4 participants