I'm not really understanding the rev=false
portion which comes after def alphabetize
:
def alphabetize (arr, rev=false)
or the portion:
if rev
If someone can explain it to me in simple terms that'd be great. When I
search this question up it pops up with help as far as how it works which I understand, however I don't get arr=false
or the last line.
puts "Z-A: #{alphabetize(books, true)}"
I'm sure those learning thru CodeAcademy would appreciate the answer. This is the code for reference.
def alphabetize (arr, rev=false)
if rev
arr.sort { |item1, item2| item2 <=> item1 }
else
arr.sort { |item1, item2| item1 <=> item2 }
end
end
books = ["Heart of Darkness", "Code Complete", "The Lorax","The Prophet", "Absalom"]
puts "A-Z: #{alphabetize(books)}"
puts "Z-A: #{alphabetize(books, true)}"