Skip to content

Instantly share code, notes, and snippets.

@thedjinn
Forked from jeffkreeftmeijer/ranking.rb
Created February 16, 2011 20:48
Show Gist options
  • Save thedjinn/830163 to your computer and use it in GitHub Desktop.
Save thedjinn/830163 to your computer and use it in GitHub Desktop.
# We have four scores, two of them share the second place. This means the last
# one has to be pushed to the fourth place.
scores = [10, 9, 9, 8]
ranking, last_score, add = 0, 0, 1
rankings = scores.map do |score|
scores.index(score) + 1
end
puts scores.inspect # => [10, 9, 9, 8]
puts rankings.inspect # => [1, 2, 2, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment