Skip to content

Instantly share code, notes, and snippets.

@aptinio

aptinio/my_sort.rb

Created Aug 18, 2010
Embed
What would you like to do?
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
You can’t perform that action at this time.