• Chris Greene

    Hi! Thanks for this link. I suspect the reason for this sorting by class name is as follows:

    consider the list

    [100,”a”,5]

    we would expect that when this array is sorted we’d get 5 before 100.

    However, if mapping id to each element gave us

    [1,2,3]

    this list would aready be in sorted order*. And you would be sorting on this ground presumably because all adjacent types are different. To ensure that the sensible cmp function is called you need all like types together.

    *(yes, numbers are automatically less than any other element, so in a real example, we’d need custom types to pull this off)

  • Chris Greene

    Hi! Thanks for this link. I suspect the reason for this sorting by class name is as follows:

    consider the list

    [100,”a”,5]

    we would expect that when this array is sorted we’d get 5 before 100.

    However, if mapping id to each element gave us

    [1,2,3]

    this list would aready be in sorted order*. And you would be sorting on this ground presumably because all adjacent types are different. To ensure that the sensible cmp function is called you need all like types together.

    *(yes, numbers are automatically less than any other element, so in a real example, we’d need custom types to pull this off)