From: Klaus Stein Date: 2009-01-15T21:09:44+09:00 Subject: Re: Returning a duplicate from an Array Pierre Pat wrote: > I'd do like this: > a.select{|x| a.index(x) != a.rindex(x)}.uniq > > Now, I wouldn't know which one is more efficient, but coding wise, I > like that way :-) > If order is not important: h = Hash.new(0) a.each { |x| h[x]+=1 } h.select {|k,v| v>1 }.keys should be O(n) and with only one iteration through a. Klaus -- http://lapiz.istik.de/ The Answer is 42. And I am the Answer. Now I am looking for the Question.