Last active
January 4, 2016 17:09
-
-
Save HaiTo/8651822 to your computer and use it in GitHub Desktop.
This file contains 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
# uniq_key=>count | |
# 必要になったのでメモみたいな形。 | |
class Array | |
# return hash | |
def rollup | |
r_hs = {} | |
self.uniq.each do |sep| | |
r_hs[sep] = self.count sep | |
end | |
r_hs | |
end | |
# return ary [uniq_key,count] | |
def rollup | |
r_ar = [] | |
self.uniq.each do |sep| | |
r_ar = [self,self.count(sep)] | |
end | |
r_ar | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
多分もっと短くしても(r_ar,r_hsなしで直接returnさせられるようなワンライナー)実行速度そんな変わらないと思います(思うだけでわかりませんが)