What is wrong with this code?


#1

def alphabetize (arr, rev=false)
arr.sort!
if rev
arr.reverse!
return arr
end
numbers=[1,2,3,4,5]
puts alphabetize (numbers)


#2

Assuming that you are on sorting, you've missed alot of obvious pieces.

You missed Else, and alot.
My code:

def alphabetize(arr, rev=false)
        arr.sort!
        if rev == true
            arr.reverse!
        else
            arr.sort!
        end
    end
    numbers = [1, 8, 9, 5, 10, 6]

    puts alphabetize(numbers)
    puts numbers

Edit: End statement is really the thing being missed here.


#3

I don't see the need for running arr.sort! again in the else since it has already been run at the beginning of the method. He also shouldn't need rev==true due to the fact that the if statement will execute based on the already boolean value of 'rev'.

Edit: So to answer the first question it looks like you're just missing the 'end' for closing the if statement.


#4

I agree with levibarker. I hope Codecademy folks really clean up their act because this sort of this has come up one too many times and it just kills our precious time without adding to our understanding.


#5

"A lot" is two words. Detail, yo.


#6

Agreed. I had basically the same code that worked just fine, had all the functionality the task called for but was throwing up an error that I couldn't just skip over. There should be a way to skip to the answer. I know some people will abuse it, but the rest of us are just like "wha?"