• ScreamingFirehawk
    link
    fedilink
    arrow-up
    15
    ·
    1 day 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
      ·
      1 day 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
      ·
      1 day 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.