New issue
Advanced search Search tips
Starred by 2 users

Issue metadata

Status: Duplicate
Merged: issue v8:90
Owner: ----
Closed: Aug 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug



Sign in to add a comment

Incorrect result of works "Array.prototype.sort" function

Reported by i.prilad...@gmail.com, Jul 28 2016

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0

Steps to reproduce the problem:
Code:

  var testArray = [];
  for(var i=0; i<11; i++){
	testArray.push({index:i});
  }

  console.log(testArray[0].index,
           testArray[Math.floor(testArray.length/2)].index);

  testArray.sort();
  console.log(testArray[0].index,
           testArray[Math.floor(testArray.length/2)].index);

Result in Chrome:

  0 5
  5 1

Result in Firefox:

  0 5
  0 5

What is the expected behavior?
All array elements are compared as strings "[object Object]". Consequently their location in the array does not change.

What went wrong?
Why swap the elements at indices '1' and 'Math.floor(testArray.length/2)'

Did this work before? No 

Chrome version: 51.0.2704.103  Channel: stable
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version:
 

Comment 1 by kojii@chromium.org, Jul 29 2016

Components: -Blink Infra>Client>V8
Labels: -OS-Windows OS-All
Status: Untriaged (was: Unconfirmed)
Confirmed in Canary. Edge produces the same result as Firefox.
Components: -Infra>Client>V8 Blink>JavaScript
Better triage label...
Cc: adamk@chromium.org
Components: -Blink>JavaScript Blink>JavaScript>Language
Status: Available (was: Untriaged)

Comment 4 by adamk@chromium.org, Aug 10 2016

Mergedinto: v8:90
Status: Duplicate (was: Available)
This is working as intended: sort is not guaranteed to be stable (see various historical discussion on  issue v8:90 ).

Sign in to add a comment