Why does this work?


#1



https://www.codecademy.com/courses/ruby-beginner-en-nOho7/0/6?curriculum_id=5059f8619189a5000201fbcb


When I hit save and submit, it works, but it doesn't sort my numbers! I would like to know how the code is actually supposed to look.


Replace this line with your code. 
def alphabetize(arr, rev=false)
    arr.sort!
    if rev == true
        arr.reverse!
    else
        return arr
    end
end
numbers = [8,3,7,1,5]
puts numbers


#2

You should call your function:

puts alphabetize(numbers)

#3

thanks factoradic. I still don't understand why my code worked though. I guess it is just a bug.


#4

You're welcome :slight_smile:

Why should not it work? Your function is correct. It's your choice if you want to call the function or not. Codecademy checks only whether the function works correctly.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.