12

Javascript Developers­čśé

Comments
  • 1
    Javascript devs who dont read the docs.

    Well, any dev that doesn't read the docs really.
  • 2
    Having stringy sort by default is actually better because converting to integer sort is as simple as arr.sort((a, b) => a - b) but if it was integer sort by default, you would have to do
    arr.sort((a, b) => {
    if (a < b) return -1
    if (a > b) return 1
    return 0
    });
    to convert it to stringy sort.
  • 3
    How about the correct sort depending on the array containing numbers or strings? Like in all normal languages?
  • 3
    Or an extra lexicographicSort()?
  • 0
    Meh, just don't take random sorting algorithm for granted. It will save the embarrassment.
  • 0
    @vintprox I’d call it surpriseSort()
  • 0
    @Lensflare it wasn't a reply to your statement ­čśĆ
  • 2
    @Lensflare If you sort an array that only contains numbers it'll sort correctly, it only sorts in a "stringy" way if all elements except one are strings. In all other cases the behavior is undefined because the standard dictates that the relation function must be transitive and ">" on a mixed set of numbers and strings isn't transitive.
Add Comment