From: botp Date: 2009-10-05T22:27:08+09:00 Subject: Re: Count the number of times an element occurs in an array On Mon, Oct 5, 2009 at 5:24 PM, Jim Burgess wrote: > I need to count the number of times an element occurs in an array. > just for fun >> a = ["a", "b", "a", "b", "b"] => ["a", "b", "a", "b", "b"] >> a.group_by{|x|x}.map{|x,y| [x,y.size]} => [["a", 2], ["b", 3]] kind regards -botp