Skip to content

Array<number>.sort() uses lexicographic comparator by default #32593

@ghost

Description

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:
typed arrays
default comparator
lexicographic comparator
numeric comparator

Code

let a: Array<number> = [12,4];
a.sort();
console.log(a);

Expected behavior:
[4, 12]
Actual behavior:
[12, 4]
Playground Link:
https://codepen.io/greddyatpt/pen/aepoaN?editors=1111

Related Issues:
#18286 is related but it recommends a breaking change. Instead, the default comparator should take the element type into consideration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions