Skip to content

Instantly share code, notes, and snippets.

View rsim's full-sized avatar

Raimonds Simanovskis rsim

View GitHub Profile
def rank(arr)
count = {}
arr.each{|item| count[item] = (count[item]||0) + 1}
rank = 1 # initial ranking
ranking = {}
count.keys.sort.reverse.each{|item| ranking[item] = rank; rank += count[item]}
arr.map{|item| ranking[item]}
end