From: Victor Reyes Date: 2008-05-23T01:27:42+09:00 Subject: Re: Is rdoc (http://www.ruby-doc.org/core/) complete? ------=_Part_13422_1027514.1211473662614 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thank you all. Jes=FAs, thank you for the code snippet. On Thu, May 22, 2008 at 10:02 AM, Jes=FAs Gabriel y Gal=E1n < jgabrielygalan@gmail.com> wrote: > On Thu, May 22, 2008 at 3:11 PM, Victor Reyes > wrote: > > Please forgive my ignorance and thank you for the information. > > > > I have an array of integers with a minimum of 9 elements and a maximum = of > > 81. > > I need to count the frequency of each digit (1..9). > > That's why I was looking into the use of *find_all* or some other util > that > > would make my code simple. Otherwise I would have to loop and count the > old > > fashion way. > > > > This is a typical way: > > irb(main):001:0> a =3D [1,2,3,4,3,2,1,2,3,4,5,6,5,4,3,4,5,6,7,8,7,8,9] > =3D> [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 7, 8, 7, 8, 9= ] > irb(main):002:0> h =3D Hash.new {|h,k| h[k] =3D 0} > =3D> {} > irb(main):003:0> a.each {|x| h[x] +=3D 1} > =3D> [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 7, 8, 7, 8, 9= ] > irb(main):004:0> h > =3D> {5=3D>3, 6=3D>2, 1=3D>2, 7=3D>2, 2=3D>3, 8=3D>2, 3=3D>4, 9=3D>1, 4= =3D>4} > > or: > > irb(main):005:0> h2 =3D Hash.new(0) > =3D> {} > irb(main):006:0> a.each {|x| h2[x] +=3D 1} > =3D> [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 7, 8, 7, 8, 9= ] > irb(main):007:0> h2 > =3D> {5=3D>3, 6=3D>2, 1=3D>2, 7=3D>2, 2=3D>3, 8=3D>2, 3=3D>4, 9=3D>1, 4= =3D>4} > > > > Jesus. > > ------=_Part_13422_1027514.1211473662614--