Help with Clarity


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)
    if rev == true
        return array.reverse!
    else return array.sort!

numbers = [ 6, 5, 8, 11]

puts numbers


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.


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