> Jimmy Kofler wrote:
>> Jeremy Woertink wrote:
>> I actually had to ... find all the duplicate account 
>> numbers and the number of times they were duplicated and ... .
>> ...
>> ~Jeremy
> 
> 
> A much less verbose 'nil' fix of the original version would be to use 
> [v] instead of v:
> 
> a = [nil,1,2,2,3,nil]
> p a.uniq.map {|v| (a - [v]).size < (a.size - 1) ? [v] : 
> nil}.compact.flatten
> => [nil, 2]
> 

This fix does not work for a = [nil,1,2,[7],2,[7],3,nil], but the 
previous version using "(a.size - a.nitems > 1) ? ..." does. Ruby 1.9 
though is said to introduce a non-greedy Array#flatten:

# Ruby 1.9
a = [nil,1,[7],2,2,[7],3,nil]
p a.uniq.map {|v| (a - [v]).size < (a.size - 1) ? [v] : 
nil}.compact.flatten(1)
=> [nil, [7], 2]


Cheers,

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