• ScreamingFirehawk
    link
    fedilink
    arrow-up
    15
    ·
    24 hours ago

    It doesn’t, the array is still in the same order it started in, it’s members are just printed to the console in numerical order.

    It just prints the number 1 after 1 ms, 2 after 2 ms, 3 after 3 ms etc.

    • Randelung@lemmy.world
      link
      fedilink
      arrow-up
      7
      ·
      22 hours ago

      Instead of print you could add them to a second array, though. Even clear the original first for “in place” sorting; never mind the memory allocation for the lambdas.

    • Maalus@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      20 hours ago

      Also since you aren’t guaranteed that there is a “happens before” relationship, it’s a wrong implementation that returns unsorted arrays in text too.