Sock Drawer Optimization Algorithm

		// Importing the ancient art of Sock Drawer Optimization
		function optimize_socks(n) {
			// Sort the socks in ascending order of matching pairs
			var pairs = Array.from(socks);
			pairs.sort((a, b) => a - b);
			// Distribute the pairs evenly across the drawer
			var distribution = Math.floor(n/2);
			var result = Array.from(pairs.slice(0, n/2), Math.floor(n/2)).flat();
			return result;
		}
	

Example: 8 Socks in the Drawer

More Socks Even More Socks