Skip to content

Instantly share code, notes, and snippets.

@gaboesquivel
Created June 18, 2013 16:26
Show Gist options
  • Save gaboesquivel/5806901 to your computer and use it in GitHub Desktop.
Save gaboesquivel/5806901 to your computer and use it in GitHub Desktop.
shitty sort
class Page < ActiveRecord::Base
attr_accessible :body, :category_id, :title
belongs_to :category
def self.bettys_sort_asc
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_desc
array = [[1, 2], [1, 1], [2, 2], [2, 1], [3, 1]]
puts "Original --> " + array.to_s
array_sorted = array.sort{|x,y| y <=> x}
puts "Sorted --> " + array_sorted.to_s
end
def self.bettys_sort_y_asc
array = [[1, 2], [1, 1], [2, 2], [2, 1], [3, 1]]
puts "Original --> " + array.to_s
array_sorted = array.sort{|x,y| x[1] <=> y[1]}
puts "Sorted --> " + array_sorted.to_s
end
def self.bettys_sort_x_asc
array = [[1, 2], [1, 1], [2, 2], [2, 1], [3, 1]]
puts "Original --> " + array.to_s
array_sorted = array.sort{|x,y| x[0] <=> y[0]}
puts "Sorted --> " + array_sorted.to_s
end
def self.bettys_sort_y_desc
array = [[1, 2], [1, 1], [2, 2], [2, 1], [3, 1]]
puts "Original --> " + array.to_s
array_sorted = array.sort{|x,y| y[1] <=> x[1]}
puts "Sorted --> " + array_sorted.to_s
end
def self.bettys_sort_x_desc
array = [[1, 2], [1, 1], [2, 2], [2, 1], [3, 1]]
puts "Original --> " + array.to_s
array_sorted = array.sort{|x,y| y[0] <=> x[0]}
puts "Sorted --> " + array_sorted.to_s
end
def self.bettys_sort_reverse
array = [[1, 2], [1, 1], [2, 2], [2, 1], [3, 1]]
puts "Original --> " + array.to_s
array = reverse array
array_sorted = array.sort{|x,y| x <=> y}
array = reverse array
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
def self.all_sorts
puts "bettys_sort_asc"
bettys_sort_asc
puts "bettys_sort_desc"
bettys_sort_desc
puts "bettys_sort_y_asc"
bettys_sort_y_asc
puts "bettys_sort_x_asc"
bettys_sort_x_asc
puts "bettys_sort_y_desc"
bettys_sort_y_desc
puts "bettys_sort_x_desc"
bettys_sort_x_desc
puts "bettys_sort_reverse"
bettys_sort_reverse
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment