Help with Clarity


#1

10/5= Sorting with control flow.

My code was accepted, though with this error in the editor.

undefined local variable or method `array' for #

this line is confusing me. before, the 'undefined variable or method', was one of the numbers in my array. Help with clearing this up is much appreciated.

def alphabetize(arr, rev = false)
    array.sort! 
    if rev == true
        return array.reverse!
    else return array.sort!
    end
end

numbers = [ 6, 5, 8, 11]

alphabetize(numbers)
puts numbers


#2

In the definition the variable arr is given as a parameter but in the function the (undefined) variable used is array. Change this to arr so it is defined.


#3

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