@[email protected]M to Fun Loops ▶️@midwest.socialEnglish • 13 days ago[R] Stupidest ways people have solved coding interviewsloops.videoexternal-linkmessage-square36fedilinkarrow-up179arrow-down15
arrow-up174arrow-down1external-link[R] Stupidest ways people have solved coding interviewsloops.video@[email protected]M to Fun Loops ▶️@midwest.socialEnglish • 13 days agomessage-square36fedilink
minus-square@[email protected]linkfedilink15•13 days agoIt 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.
minus-square@Randelunglink7•13 days agoInstead 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.
minus-square@Maaluslink2•13 days agoAlso since you aren’t guaranteed that there is a “happens before” relationship, it’s a wrong implementation that returns unsorted arrays in text too.
Why does the sort one work? 🤨
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.
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.
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.