Skip to content

Instantly share code, notes, and snippets.

@aptinio
Created August 18, 2010 03:01
Show Gist options
  • Save aptinio/533218 to your computer and use it in GitHub Desktop.
Save aptinio/533218 to your computer and use it in GitHub Desktop.
class Array
def my_sort
arr = self.clone
sorted = false
until sorted
arr.each_with_index do |e, i|
if i < (arr.length - 1) && e > arr[i+1]
arr[i], arr[i+1] = arr[i+1], arr[i]
end
end
sorted = true
arr.each_with_index { |e, i| sorted = sorted && e <= arr[i+1] if i < (arr.length - 1) }
end
arr
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment