SOJS: 7.3 Socks in Space

Algorithmic Sock Sorting

Insertion sort is not just for humans, it's also for socks!

In this version, we'll merge 7.3 socks in space using the insertion sort algorithm.

Here are the steps:

  1. Grab 7.3 socks from the space station's sock drawer.
  2. Sort them in order of size, because who needs color when you have size, right?
  3. Insert each sock into the sorted list, like a space-age filing system.
  4. Repeat until all socks are sorted, or until you lose all sense of sanity.

Example Sock Data

Size Color
6 Red
8 Blue
9 Green
7.3 Yellow
10 Orange

Code

      
function insertionSort(socks) {
  for (let i = 1; i < socks.length; i++) {
    let sock = socks[i];
    let j = i - 1;
    while (j >= 0 && socks[j] > sock) {
      socks[j + 1] = socks[j];
      j--;
    }
    socks[j + 1] = sock;
  }
  return socks;
}
    
  

Next Steps

Want to learn more about other algorithms for sorting socks in space?

Disclaimer

This content is completely fictional and not meant to be taken seriously. Or is it?