• @jormaig@programming.dev
    link
    fedilink
    121 year ago

    Because when it’s sorting some of them as ints and some of them as strings. JavaScript has implicit conversion to string.

      • @jormaig@programming.dev
        link
        fedilink
        41 year ago

        Only if one of them is a string right? If you have only numbers then it works fine right? Right? (Please say that I’m right 😭)

        • @kevincox@lemmy.ml
          link
          fedilink
          5
          edit-2
          1 year ago

          No. It always compares by converting to string. I actually think this is more consistent then having different behaviour if you have a string somewhere in your list.

          Basically the default comparator is a.sort((a, b) => `${a}` < `${b}` ? -1 : 1).