Skip to content

Instantly share code, notes, and snippets.

@hayduke19us
Created December 11, 2015 15:26
Show Gist options
  • Save hayduke19us/beb9d34948d38128277b to your computer and use it in GitHub Desktop.
Save hayduke19us/beb9d34948d38128277b to your computer and use it in GitHub Desktop.
User = Struct.new("User", :number, :position)
def matching_number?(last, current)
last.number == current.number
end
def create_users(count)
array = []
count.times do
u = User.new
u.number = rand(0..50)
array.push(u)
end
array
end
sorted = create_users(100).sort_by(&:number)
last_user = sorted.first
sorted.each_with_index do |u, i|
u.position = i + 1
u.position = last_user.position if matching_number?(last_user, u)
last_user = u
end
puts sorted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment