Incorrect output of sort() function in console
Reported by
kidult.f...@gmail.com,
Sep 19
|
|||
Issue descriptionUserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36 Steps to reproduce the problem: 1. type [-5, -4, -3, -2, -1, 0, 0, 1, 2, 3, 4, 5].sort((x,y) => x<y) in console What is the expected behavior? output [5, 4, 3, 2, 1, 0, 0, -1, -2, -3, -4, -5] What went wrong? output [0, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5], incorrect result Did this work before? No Chrome version: 69.0.3497.81 Channel: stable OS Version: 69 Flash Version: something wrong with sorting implementation this bug doesn't exist in firefox
,
Sep 19
Able to reproduce the issue on chrome reported version# 69.0.3497.81 using Ubuntu 17.10. But seen different behavior on latest chrome# 71.0.3555.0(please find the attached screenshots for the same). @Reporter: Please find the attached screenshots for your reference and provide your feedback on it and also please check the comment# 1. Thanks!
,
Sep 19
Yes as per #1 sort is stable in Chrome 71 so this is no longer an issue.
,
Sep 19
Er, I forgot to show the correct spec-compliant comparison function to sort in descending order: (x,y) => y-x As for why Firefox still sorts with an incorrect comparison function, it's just their implementation quirk, something one never should rely upon. |
|||
►
Sign in to add a comment |
|||
Comment 1 by woxxom@gmail.com
, Sep 19