>Posted by Peña, Botp (Guest) on 21.08.2007 10:31
>
> could we simplify it like
>
> irb(main):014:0> a
> => [1, 1, 2, 2, 2, 4, 3]
> irb(main):015:0> a.uniq.select{|e| (a-[e]).size < a.size - 1}
> => [1, 2]


Sure.

ruby -e  'a = [nil,1,2,2,3,nil]'  -e 'p a.uniq.select{|e| (a-[e]).size < 
a.size - 1}'
=> [nil, 2]

So we do not need to fix the original version to handle nil correctly:

ruby -e  'a = [nil,1,2,2,3,nil]' -e 'p (a.size - a.nitems > 1) ? ([nil] 
+ a.uniq.map {|v| (a - [v]).size < (a.size - 1) ? v : nil}.compact) : 
(a.uniq.map {|v| (a - [v]).size < (a.size - 1) ? v : nil}.compact)'
=> [nil, 2]


Cheers,

j.k.
-- 
Posted via http://www.ruby-forum.com/.