Skip to content

Instantly share code, notes, and snippets.

@zliang-min
Created June 17, 2011 02:50
Show Gist options
  • Save zliang-min/1030765 to your computer and use it in GitHub Desktop.
Save zliang-min/1030765 to your computer and use it in GitHub Desktop.
def sleep_sort(a)
result = []
a.map { |e| Thread.new { sleep e; result << e } }.each { |t| t.join }
result
end
puts sleep_sort([7, 5, 8, 6, 4, 9, 2, 3, 1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment