From: Jim Burgess Date: 2009-10-05T18:24:49+09:00 Subject: Count the number of times an element occurs in an array Hi, I need to count the number of times an element occurs in an array. At the moment I'm doing it like this: a = ["a", "b", "a", "b", "b"] b = a.uniq c = [] 0.upto(b.length-1) do |e| d = 0 0.upto(a.length-1) do |f| if b[e] == a[f] d += 1 end end c << d end print b, c > ["a", "b"] [2, 3] This works, but seems really clumsy. Can anyone give me any tips on what I could improve? Cheers. -- Posted via http://www.ruby-forum.com/.