Skip to content

Instantly share code, notes, and snippets.

@gaboesquivel
Created June 18, 2013 16:08
Show Gist options
  • Save gaboesquivel/5806678 to your computer and use it in GitHub Desktop.
Save gaboesquivel/5806678 to your computer and use it in GitHub Desktop.
bettys sort
def self.bettys_sort
array = [[1, 2], [1, 1], [2, 2], [2, 1], [3, 1]]
puts "Original --> " + array.to_s
array_sorted = array.sort{|x,y| x <=> y}
puts "Sorted --> " + array_sorted.to_s
end
def self.bettys_sort_y
array = [[1, 2], [1, 1], [2, 2], [2, 1], [3, 1]]
array = reverse(array)
puts "Original --> " + array.to_s
array_sorted = array.sort{|x,y| x <=> y}
array_sorted = reverse array_sorted
puts "Sorted --> " + array_sorted.to_s
end
def self.reverse array
new_array = []
array.each do |ar|
new_array << ar.reverse
end
new_array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment