From: Chris Hulan Date: 2013-03-29T23:47:23+09:00 Subject: Re: Program with shuffle program --bcaec54c4e003fc29f04d9115941 Content-Type: text/plain; charset=ISO-8859-1 this line: return shuffled if unshuffled.index == 0 I think you mean return shuffled if unshuffled.length == 0 On Fri, Mar 29, 2013 at 10:40 AM, Vincent Stowbunenko wrote: > I am trying to make my own shuffle method instead of the build-in one. > From looking at the debugging program, the recursive_shuffle does not > return when unshuffled.length == 0. What went wrong there? > > See code below: > > [CODE] > class Array > > def shuffle > return self if self.length < 1 > recursive_shuffle self, [] > end > > def recursive_shuffle unshuffled, shuffled > random_index = rand(unshuffled.length) > shuffled << unshuffled.slice!(random_index) > return shuffled if unshuffled.index == 0 > recursive_shuffle unshuffled, shuffled > end > > end > > words = ['history', 'downstairs', 'adapter', 'mist', 'circumstance', > 'coast', 'fender', 'war', 'alcohol', 'attendance'] > puts words.shuffle > [\CODE] > > -- > Posted via http://www.ruby-forum.com/. > > --bcaec54c4e003fc29f04d9115941 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
this line:
=A0return shuffled if unshuffled.index =3D=3D 0
=

=
I th= ink you mean=A0
=A0return shuffled if unshuffled.length=A0=3D=3D 0
--bcaec54c4e003fc29f04d9115941--