New issue
Advanced search Search tips

Issue 6851 link

Starred by 1 user

Issue metadata

Status: Duplicate
Merged: issue 90
Owner: ----
Closed: Sep 2017
HW: ----
NextAction: ----
OS: ----
Priority: ----
Type: Bug



Sign in to add a comment

Javascript array sort equal elements unstable

Reported by class.kb...@gmail.com, Sep 22 2017

Issue description

Version: Version 61.0.3163.100 (Official Build) (64-bit)
OS: Windows 10, MacOS Sierra 10.12.6
Architecture: x64

What steps will reproduce the problem?
1. Open Dev tools
2. Paste and execute : [1,2,3,4,5,6,7,8,9,10,11].sort((a,b) => 0);

What is the expected output?
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

What do you see instead?
[6, 1, 3, 4, 5, 2, 7, 8, 9, 10, 11]


If there are 10 elements I get the expected results:
[1,2,3,4,5,6,7,8,9,10].sort((a,b) => 0);
(10) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

The same test on IE 11, Edge, Firefox and Safari results in restoring the inital order. I believe the sorting optimization after 10 elements is the reason the elements change. I understand the specification doesn't guarantee a stable sort order (http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.11). I suggest restoring the initial order after sort finishes when all elements return 0 would result in the api being more user-friendly.

 
Just found https://bugs.chromium.org/p/v8/issues/detail?id=90 I guess I missed it the first search through.
Mergedinto: 90
Status: Duplicate (was: Untriaged)

Sign in to add a comment