Hi,

Am Montag, 10. Aug 2009, 00:54:31 +0900 schrieb Tom Ha:
> 
>    original = [1, 2, 3, 3, 3, 3, 4, 4, 5]
> 
> The result should look like this:
> 
>    result = {"3"=>4, "4"=>2}

Here are two:

  original.inject({}) { |h,e| h[e] ||= 0 ; h[e] += 1 ; h }

and

  h = Hash.new { |h,k| h[k] = 0 }
  original.each { |e| h[e] += 1 }
  h

then

  h.reject! { |k,v| k == 1 }

Bertram


-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de