Skip to content

Instantly share code, notes, and snippets.

@HaiTo
Last active January 4, 2016 17:09
Show Gist options
  • Save HaiTo/8651822 to your computer and use it in GitHub Desktop.
Save HaiTo/8651822 to your computer and use it in GitHub Desktop.
# 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
@HaiTo
Copy link
Author

HaiTo commented Jan 27, 2014

多分もっと短くしても(r_ar,r_hsなしで直接returnさせられるようなワンライナー)実行速度そんな変わらないと思います(思うだけでわかりませんが)

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