html SOJs: Sock Hierarchy Ranking Algorithm Source Code

SOJs Sock Hierarchy Ranking Algorithm Source Code

This code is for the discerning SOJs user who wants to know the intricacies of the SOJs algorithm.

				function sortSocks(s1, s2) {
					if (s1 === s2) return 0;
					if (s1 > s2) return 1;
					return -1;
				}
				
				function rankSocks(socks) {
					so = socks.sort(sortSocks);
					return so;
				}
			

The algorithm works by sorting a list of socks in descending order, with the most majestic sock first.

Example usage:

For the full source code, visit /algorithm/source-code/4-8

For more information on SOJs, visit /algorithm/4-8