Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-34321

Javascript custom array sorting is wrong

    XMLWordPrintable

Details

    Description

      Sorting a javascript array with a custom sorting function give a wrong result:

      Test code :

      var array = []
      
      array.push({name:"a", value:0})
      array.push({name:"b", value:0})
      
      array.sort(function(a,b) { return a.value - b.value })
      
      print(array[0].name + "," + array[1].name)
      
      

      Expected result is: "a,b"

      Result is : "b,a"

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            laknoll Lars Knoll
            x-krys Christopher Courtois
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes