Skip to content

feat: a default sort over numbers only is numeric, and one over objects asks for a comparator - #72

Merged
kommander merged 1 commit into
devfrom
new/sort-numbers
Nov 24, 2026
Merged

kommander merged 1 commit into
devfrom
new/sort-numbers

Conversation

@kommander

Copy link
Copy Markdown
Contributor

A default sort()/toSorted() over numbers only is numeric ([10, 9, 1] → [1, 9, 10]), and one that would compare objects throws a TypeError asking for a comparator.
Why: JavaScript's text order for numbers and [object Object] order for objects are quirks agents trip on; documented as deliberate differences.

…ts asks for a comparator

[10, 9, 1].sort() is [1, 9, 10] (also toSorted), a deliberate difference from JavaScript, which compares numbers
as text. A default sort that would compare an object throws a TypeError at the call asking for a comparator. Any
other mix of elements keeps the string order.
@kommander
kommander merged commit 3da1858 into dev Nov 24, 2026
1 check passed
@kommander
kommander deleted the new/sort-numbers branch November 24, 2026 23:20
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.

1 participant