• Seigest
    link
    fedilink
    English
    231 year ago

    Didn’t belive it. tried it. died a little more inside.

  • @poopsmith
    link
    English
    181 year ago

    From MDN:

    If compareFn is not supplied, all non-undefined array elements are sorted by converting them to strings and comparing strings in UTF-16 code units order.

    So, if you’re trying to sort numbers, [6, -2, 2, -7].sort((a, b) => a - b)

    • @Solumbran
      link
      English
      41 year ago

      That might be explainable, but doesn’t make it logical or acceptable.

  • @Blamemeta
    link
    English
    171 year ago

    Its converting numbers to strings.

    • @EatMyDick
      link
      English
      -31 year ago

      Yes. Asute observation captain.

  • @_sideffect
    link
    English
    141 year ago

    Imagine going for a JavaScript coding interview and failing because of this 😂

    • @[email protected]
      link
      fedilink
      English
      41 year ago

      That’s a good point lol, I haven’t done a js interview yet but it’d probably be kinda rough trying to remember random shit like this.

    • @EatMyDick
      link
      English
      -3
      edit-2
      1 year ago

      Meh, it’s a day 2 thing to understand how shitty JS deals with numbers. Good devs will cover their asses by default.

  • @sulungskwa
    link
    English
    91 year ago

    Blessed are those that use Array.sort without passing it arguments