Subject: Re: How to get non-unique elements from an array?
From: Sylvain Joyeux <sylvain.joyeux@ l e n u o >
Date: Wed, 19 Oct 2005 08:11:14 +0900
References: 160697161119161135
In-reply-to: 161135
> ? ? ? ?run_benchmark(bx, 'jegII', iterations) { seen =
> Hash.new(0);a.select { |e| (seen[e] += 1) > 1 }.uniq }
I think you could improve this one a bit by simply doing
{ seen = Hash.new(0); a.select { |e| (seen[e] += 1) == 2 } }
Regards
Sylvain