• katy ✨
    link
    fedilink
    5211 months ago

    Programming Javascript is roughly the equivalent of hitting your head with a hammer or trying to uninstall McAfee.

    • @dohpaz42
      link
      English
      411 months ago

      As if Javascript wasn’t complex enough, let’s introduce TypeScript and Coffescript and then write transpilers so we can convert said languages back into Javascript, which we could have done in the first place.

      • @[email protected]
        cake
        link
        fedilink
        English
        1811 months ago

        Nobody uses coffeescript anymore, and typescript is there to make things easier not harder.

      • Excel
        link
        fedilink
        English
        111 months ago

        These languages only exist because JS is so dumb in the first place

      • @devfuuu
        link
        English
        111 months ago

        And all the new versions of all the above constantly being released. I’m so glad I don’t use those languages anymore.

  • @[email protected]
    link
    fedilink
    1911 months ago

    Use stringly-typed everything, and always padStart your numbers.
    Saves running into issues with numbers outside the 52-bit integer range.
    And padding start means you don’t have to worry about pesky sort functions.

    Just don’t do maths. Simple.

    Maybe you could do a manual sort.
    Provide a “captcha” prompt, and ask which comes first in the list… You know, to make sure the user is a human! And you get free sorting.

    • @kunehoOP
      link
      2011 months ago

      Provide a “captcha” prompt, and ask which comes first in the list… You know, to make sure the user is a human! And you get free sorting.

      I mean, this strangely is a compelling idea…

      • TWeaK
        link
        fedilink
        1411 months ago

        I always try to prove myself human with wrong answers. Typically the first screen is an AI training screen, then the next screen is one the computer knows but wants to see if you know. By answering the first one wrong and the second correct, I’m hoping to poison the data.

  • Ategon
    link
    fedilink
    16
    edit-2
    11 months ago

    Note if you put the image link in the url bar of the post rather than the body it lets people see it while scrolling (url + title can be edited so you can edit it to do that still if you want)

    • @kunehoOP
      link
      711 months ago

      thanks!

      using 3rd party client (and first “image post” I’ve made on this platform) and wasn’t sure how image post should be made.

  • @[email protected]
    link
    fedilink
    711 months ago

    I couldn’t believe it, tried it out, what the actual heck? I mean I get all these weird string vs number comparison but sorting actual numbers and this comes out? What kind of drugs were the designers of javascript (or at least this function) on… Who thought it was a good idea to sort numbers lexicographically??

  • @[email protected]
    link
    fedilink
    411 months ago

    Well, 3 out of 5 correct ain’t bad. With some more trial runs we might get this thing nailed!

  • @[email protected]
    link
    fedilink
    211 months ago

    So, I think just yesterday or the day before someone on here was saying we shouldn’t make fun of JavaScript anymore.

    • @roboter5123
      link
      111 months ago

      Deploying surprise in 3, 2… Hold up for a seco d that wasn suppossed to happen.

  • @Freethewhat
    link
    111 months ago

    Ugh, I just ran into this in Terraform. Why is this a thing?

    • @[email protected]
      link
      fedilink
      811 months ago

      It’s just sorted alphabetically (technically it is the UTF16 code order). To be fair it’s a sane default for most use cases. In JS case you can define a very simple callback to change the behavior to numeric sorting (a,b => a<b). Many other sorters provide a flag instead, but numeric sorting is seldom the default as it is not as useful most of the time in weakly typed languages.

      • Excel
        link
        fedilink
        English
        211 months ago

        weakly typed languages

        Well, looks like we found the problem right there

    • @[email protected]
      link
      fedilink
      18
      edit-2
      11 months ago

      Array.prototype.sort if no callback is passed to it will coerce non-undefined elements to strings when sorting. It does do that.

      To sort numbers passing a function like (a, b) => a - b is good enough.