# ruby syntax
def compare_them (obj1, obj2)
if obj1[0].nil?
if !obj2[0].nil?
return obj1[1] <=> obj2[0]
else
if obj2[1].nil?
if obj1[1] == obj2[0]
return -1
else
return obj1[1] <=> obj2[0]
end
else
return obj1[1] <=> obj2[1]
end
end
else
if obj2[0].nil?
if obj1[1].nil?
if obj1[0] == obj2[1]
return 1
else
return obj1[0] <=> obj2[1]
end
else
return obj1[1] <=> obj2[1]
end
else
return obj1[0] <=> obj2[0]
end
end
end
foo = [[nil, 1],
[nil, 3] [1, [nil2],
4] [2, [nilnil],
5] [3, [nilnil],
6] [4, [nilnil],
7] [5, nil],
[3[nil, nil]3],
[4 [nil, nil]4],
[2 [nil, nil]5],
[1 [nil, 2]6],
[5 [nil, nil]7],
[6, 8],
[7, 9],
[8, nil],
[7, 9], [9, 10]]
foo.sort { |a1,a2| compare_them(a1, a2) }