Skip to content

Instantly share code, notes, and snippets.

@naoty
Forked from rinmu/ranking.rb
Created September 27, 2012 10:35
Show Gist options
  • Save naoty/3793367 to your computer and use it in GitHub Desktop.
Save naoty/3793367 to your computer and use it in GitHub Desktop.
配列の要素をランキングする
class Array
def ranks
rank = self.sort.reverse
self.map {|n| rank.index(n) + 1 }
end
end
describe Array do
describe '#ranks' do
it { [100, 80, 90, 90, 90, 70, 70, 80].ranks.should == [1, 5, 2, 2, 2, 7, 7, 5] }
end
end
@naoty
Copy link
Author

naoty commented Sep 27, 2012

% rspec ranking.rb
.

Finished in 0.00088 seconds
1 example, 0 failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment