#### Topic: Trouble Writing My Own Sort Method

I know there is a method called "sort" that can be called on arrays but I want to write my own to get a feel for Ruby. I'm getting an error I can't understand. Can anyone help?

Code:

~~~~~~~~~~~~~~~~~

unsorted = ['cat','ate','at','ball','beetle','bat']

sorted = []

def recursive_sort unsorted, sorted

while unsorted.length > 0

if unsorted.length == 1

sorted.push unsorted[0]

unsorted.pop

else

counter = unsorted.length

a = 1

y = unsorted[0]

while counter > 0

if y > unsorted[a] #LINE 13

y = unsorted[a]

end

counter = counter-1

a = a+1

end

sorted.push y

unsorted.delete(y)

end

end

puts sorted

end

recursive_sort unsorted, sorted

~~~~~~~~~~~~~~~~~~

I get this error message:

test.rb:13:in '>': comparison of String with nil failed (ArgumentError)

Any help would be appreciated!