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

Improve sorting of collection numbers to be more numeric like, as Human's would expect #2601

Conversation

KaelenProctor
Copy link
Contributor

@KaelenProctor KaelenProctor commented Feb 9, 2025

Problem

Collector numbers are not numbers but strings (an unexpectedly large set of non-numbers) and thus the current sort will sort something like "38" before "4"

Solution

Padding the collector numbers with 0 on the left to normalize them is the main improvement. Other tricks based on the sorts of collector number formats include:

  • Remove any trailing non-number before padding, such as for "97★" (promo version), "34†" (starter with extra reminder text), or "10c" (art variant). That allows the numeric portion to be compared as expected
  • Split by dash (-) and pad both sides the same, such as for "C14-145" (The List) or "2024-03" (Planeswalker Champ promo). That allows the set and then the collector number to be sorted

I also tried using a natural sorting library like https://www.npmjs.com/package/natural-orderby but that resulted in some unexpected orders from what I'd expect such as:

  • 75★ < 75a < 75b
  • 8ED-72 < 2024-03 < ORI-38
  • 42 < ... < ap100 < B14 < UA03a (admittedly this case is so edge that it barely matters)

In comparison the sort I implemented gives for those cases:

  • 75a < 75b < 75★
  • 8ED-72 < ORI-38 < ... < 2024-03
  • 42 < B14 < 2024-03 < UA03a ...

Also the library uses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare which has some mobile browser incompatibility with respect to locale which the library does use.

Testing

Tested the sorts with both "Group by Set then Collector number" and "Sort just by Collector number"

Before

Sorting of collector numbers within a set:
old-sorting-within-set
Sorting of collector numbers without set grouping:
old-sorting-across-all-sets
Sorting of collector numbers with The List cards:
old-list-sorting

After

Sorting of collector numbers within a set:
new-sorting-by-set-then-number

Sorting of collector numbers without set grouping:
new-sorting-numerically-across-all-sets

Sorting of collector numbers with The List cards:
new-list-cards-sorting

Cases this doesn't handle

World championship decks, since those are in format of <competitor initials>-<number>[sb]
new-sorting-world-champ-not-correct

Unknown event cards, since those start with characters then numbers but have different total lengths
image

Collector numbers first off aren't always numbers, there are many
types containing alphabetical or non-alphanumeric characters.

The main act of normalization is to pad the collector number strings so
that numeric like values are correctly compared as human's would expect.
@dekkerglen dekkerglen merged commit f854945 into dekkerglen:master Feb 9, 2025
1 check passed
@KaelenProctor KaelenProctor deleted the feature/normalized-sorting-of-collection-numbers branch February 9, 2025 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants