Home > Uncategorized > Ruby ‘dups’

Ruby ‘dups’

I was surprised to see Ruby doesn’t have this handy function:

module Enumerable
def dups
inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys
end
end

Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.