Created
October 14, 2018 15:48
-
-
Save joel-extremo/dc5c3f2e3697be5c8ff4584d9db52641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, Absalom!"] | |
puts "A-Z: #{alphabetize(books)}" | |
puts "Z-A: #{alphabetize(books, true)}" | |
puts books |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment