• towerful@programming.dev
    link
    fedilink
    arrow-up
    24
    ·
    1 year 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.

  • Ategon@programming.dev
    link
    fedilink
    arrow-up
    19
    ·
    edit-2
    1 year 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)

    • kuneho@lemmy.worldOP
      link
      fedilink
      arrow-up
      7
      ·
      1 year 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.

  • fuck_u_spez@lemmy.fmhy.ml
    link
    fedilink
    arrow-up
    7
    ·
    1 year 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??

  • VonReposti@feddit.dk
    link
    fedilink
    arrow-up
    5
    ·
    1 year ago

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

  • CanadaPlus@lemmy.sdf.org
    link
    fedilink
    arrow-up
    3
    ·
    1 year ago

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

    • Swiggles@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      8
      ·
      1 year 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.