Created
September 27, 2012 09:41
-
-
Save ppworks/3793160 to your computer and use it in GitHub Desktop.
配列の要素をランキングする
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
#!/usr/bin/env ruby | |
def ranks scores | |
ranks = Array.new scores.size, 1 | |
prev = nil | |
rank = 0 | |
scores.each_with_index do|score, i| | |
unless prev == score | |
rank = i | |
end | |
ranks[i] += rank | |
prev = scores[i] | |
end | |
ranks | |
end | |
puts ranks([100, 90, 90, 90, 90, 80, 70]) |
rinmu
commented
Sep 27, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment