Tom Ha wrote:
> Hi there,
> 
> Assume the following array (contains doubles):
> 
>    original = [1, 2, 3, 3, 3, 3, 4, 4, 5]
> 
> What's the most efficient way to obtain a hash that tells me what
> elements of "original" have more than 1 appearance/entry (= doubles)?
> 
> The result should look like this:
> 
>    result = {"3"=>4, "4"=>2}
> 
> Thanks for your help!
> Tom-n00b

I won't argue that it's the most "efficient" but the following both 
works and is easy to understand.


irb(main):007:0> original.each do |o|
irb(main):008:1* o = o.to_s
irb(main):009:1> result[o] ||= 0
irb(main):010:1> result[o] += 1
irb(main):011:1> end
=> [1, 2, 3, 3, 3, 3, 4, 4, 5]
irb(main):012:0> result
=> {"1"=>1, "2"=>1, "3"=>4, "4"=>2, "5"=>1}
irb(main):013:0> result.delete_if {|k, v| v == 1}
=> {"3"=>4, "4"=>2}


-- 
MagickWand for Ruby - http://magickwand.rubyforge.org/