Created
June 18, 2013 16:08
-
-
Save gaboesquivel/5806678 to your computer and use it in GitHub Desktop.
bettys sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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