javascript:the function sort() will return a wrong result in chrome
Reported by
liukui1...@gmail.com,
Dec 14 2017
|
||
Issue description
UserAgent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
Steps to reproduce the problem:
`<script type="text/javascript">
var a = [1,3,5,7,9,3,4,6,8,10,11,13,15,17,19,12,14,16,18,10,20];
var b = a.sort(function(x,y){return x<y;});
console.log(b);
</script>`
the function a.sort() will get a wrong result when the length of a is over 10 in Chrome but it's OK in Firefox
What is the expected behavior?
What went wrong?
`<script type="text/javascript">
var a = [1,3,5,7,9,3,4,6,8,10,11,13,15,17,19,12,14,16,18,10,20];
var b = a.sort(function(x,y){return x<y;});
console.log(b);
</script>`
the function a.sort() will get a wrong result when the length of a is over 10 in Chrome but it's OK in Firefox
Did this work before? N/A
Chrome version: 63.0.3239.84 Channel: stable
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version:
,
Dec 14 2017
,
Dec 14 2017
Correction: if you want descending order use "return y-x". As a side note, it seems Firefox implements an additional non-spec compliant enhancement by doing a so-called stable sort - the elements for which your code returns 0 get resorted one more time via additional reverse check. |
||
►
Sign in to add a comment |
||
Comment 1 by woxxom@gmail.com
, Dec 14 2017