Part 4


#1

Please help!

I know that the following code it's working but it doesn't print out anything in the console, only give the message wrong number of arguments (0 for 1)

my code

def alphabetize(arr, rev=false)
alphabetize.sort!
end
numbers = [ 45 , 60 , 2 , 8 , 12 ]

alphabetize(numbers)
puts alphabetize


#2

The code is calling .sort! on the alphabetize method instead of just the array of numbers.

alphabetize.sort!

should be

arr.sort!

#3

Thank, but still not working

def alphabetize(arr, rev=false)
arr.sort!
puts alphabetize
end

numbers = [ 45 , 60 , 2 , 8 , 12 ]

alphabetize(numbers)


#4

The

alphabetize(numbers)

isn't being put to the console.

Whereas the

puts alphabetize

doesn't have an input to use.

Try removing the "puts alphabetize" inside the method and instead using

puts alphabetize(numbers)

at the end.


#5

OK finally I did it check it out

this was that I did

def alphabetize(arr, rev=false)
arr.sort!
end

numbers = [ 45 , 60 , 2 , 8 , 12 ]

puts "#{alphabetize(numbers)}"

This error appear when you call your method in a wrong way.

Thanks so much for your help.


#6

I think this is simplest.

def alphabetize(arr, rev=false)
arr.sort!
end

numbers = [5, 6, 2, 4]

puts alphabetize(numbers)


#7

This also works:

def alphabetize(arr, rev=false)

arr.sort!
end

numbers = [ 29, 12, 5, 81, 33 ]
alphabetize(numbers)
puts numbers