hrstt
8/1/2011 - 10:19 PM

extract duplicate value in array

extract duplicate value in array

a = [1,2,3,4,5,6,4,5]
a.inject(Hash.new 0) {|h,v| h[v]+= 1;h}.select {|h,v| v >= 2}.keys #=> [4,5]