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]