-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(collection)!: default sort comparison algorithm #10412
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10412 +/- ##
==========================================
+ Coverage 38.01% 43.18% +5.16%
==========================================
Files 239 229 -10
Lines 15471 17683 +2212
Branches 1353 1189 -164
==========================================
+ Hits 5881 7636 +1755
- Misses 9575 10003 +428
- Partials 15 44 +29
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I'm labelling this as semver-major because it changes the behaviour of |
Please describe the changes this PR makes and why it should be merged:
The documentation for
Collection#sort
andCollection#toSorted
implies that if no comparison function is passed to the method, the default comparison behaviour mirrors that ofArray.prototype.sort
– in other words, stringwise comparison by UTF-16 code points.As things stand, that's not the case. There are a couple of significant issues with the current implementation of
defaultSort
:>
operator, which preferentially performs numeric comparison of its operands.'1.0'
is sorted after1
with stringwise comparison, but'1.0' > 1
is false.I'm assuming that the intention is for the default behaviour to mirror that of
Array.prototype.sort
, and so this PR rewrites the function to follow the ECMA-262 specification for the default comparison algorithm. The docblocks are also updated to reflect this more accurately.Status and versioning classification: