Faster approach to identifying duplicates in a Ruby array
Not mine, this one. Came from bshow here
a = [1,1,5,5,2,3,99,54,54,3,7,54,54,3,19]
a.inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys.inspect # => [1, 3, 5, 54]
Trackbacks
Use this link to trackback from your own site.
Comments
You must be logged in to leave a response.