From: James Nathan Date: 2009-10-08T09:37:22+09:00 Subject: Re: Count the number of times an element occurs in an array --0-1200502849-1254962237=:14508 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hello, =A0 I am new to ruby and the rails and it seems that it will not run or open to= let me see if I have install it. is there amy way that you can help me. james --- On Mon, 10/5/09, Fleck Jean-Julien wrote: From: Fleck Jean-Julien Subject: Re: Count the number of times an element occurs in an array To: "ruby-talk ML" Date: Monday, October 5, 2009, 3:43 AM Hello, 2009/10/5 Jim Burgess : > Hi, > > I need to count the number of times an element occurs in an array. Using Enumerable.count should do the trick: a =3D ["a", "b", "a", "b", "b"] a.uniq.each do |elem| =A0 puts "#{elem}\t#{a.count(elem)}" end Produces: a=A0 =A0 =A0=A0=A02 b=A0 =A0 =A0=A0=A03 Cheers, --=20 JJ Fleck PCSI1 Lyc=E9e Kl=E9ber =0A=0A=0A --0-1200502849-1254962237=:14508--