Help me olease on 5 sorting with


#1

def alphabetize(arr, rev = false)
arr.sort! { |item1, item2| item1 <=> item2 }
if rev
arr.reverse!
end
arr
end

numbers = [42, 1816, 43, 141, 1680, 678, 244]
alphabetize(numbers)
puts(numbers)
And this is working.
On a side note, this could be shorten like this:

def alphabetize(arr, rev=false)
rev ? arr.sort!.reverse! : arr.sort!
if rev==true
arr.reverse!
end

puts numbers
end


#2

I'm not exactly sure what's going on with all your code but this is what I did and it worked fine.

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