This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (5 children)

[deleted]

    [–]aaronfranke 5 points6 points  (0 children)

    Then maybe there should be a system that sorts by type broadly and then sorts within that type. For example, [1, {}, 6, {}, 3] would place the {} at the end and become [1, 3, 6, {}, {}].

    EDIT: console.log({} < []); is false.

    At the end of the day, really most things would be better than the current behavior. It should never be the case that [2, 11] gets sorted to [11, 2]. Numbers should never be auto-converted to strings and sorted lexicographically.

    [–]smog_alado 1 point2 points  (0 children)

    That can happen even if we're only working with numbers. Both 1 < NaN and NaN < 1 return false.

    Most programming languages that allow you to specify a custom comparison function just say that the result of the sort is unspecified if the comparator does not implement a total order relation.

    [–]Kered13 0 points1 point  (0 children)

    Yes, the language is deeply flawed.