Sort It Out: The Number-Sorting Algorithms of Sock Drawer

Sorting algorithms, the unsung heroes of the sock drawer. Without them, our socks would be lost forever in a tangled mess of chaos.

The Bubble Sort

A classic. It's like when you sort a load of laundry by throwing the socks in the washing machine and letting it sort them out.

			@function bubbleSort(arr) {
				@var n = arr.length
				for (i = 0; i < n-1; i++) {
					for (j = 0; j < n-i-1; j++) {
						if (arr[j] < arr[j+1]) {
							@temp = arr[j]
							arr[j] = arr[j+1]
							arr[j+1] = temp
						}
					}
				}
				return arr
			}
		

This one's a real gas. Just like when you're trying to find that one missing sock that always gets eaten by the washing machine.

Insertion Sort: The Sneaky Sock Thief Selection Sort: The Sock Inspector Merge Sort: The Sock Matcher