ruby - Map a ranking over an array of positive scores -
i have list of positive scores:
[98.5, 85, 50, 50, 23, 0, 0, 0] i assign ranks these scores:
[1, 2, 3, 3, 4, 5, 5, 5] when 2 consecutive scores have same value, same rank. idea how solve in functional fashion?
(posted in haskell , ruby because think both solutions feasible , can ported)
in ruby:
a = [98.5, 85, 50, 50, 23, 0, 0, 0] sorted = a.sort.uniq.reverse a.map{|e| sorted.index(e) + 1} # => [1, 2, 3, 3, 4, 5, 5, 5]
Comments
Post a Comment