10.5. Sorting with control flow


#1

Hi guys,

This is what I got for 10.5 and it works.

def alphabetize(arr,rev=false)
alphabetize.sort!
if rev == true
puts arr.reverse!
end
number = [2,4,7,8,9,10,15]
puts alphabetize {|number|}
end

Im confused cuz I realized other's answers are different from mine. I need verification.
Thanks


#2

Hi Aden,

There will always be several ways to solve a problem in code, so don't worry if your code is different from other peoples'. If your code works and you're being passed, don't worry about it :)
Your code wouldn't work for me though, it was throwing an error on the console, so maybe you should compare your code to some other peoples' this time.


#3

Looks like you're trying to sort the method instead of the array. So instead of alphabetize.sort! you should have arr.sort!