Last active
June 28, 2018 02:26
-
-
Save ph3nx/8510875 to your computer and use it in GitHub Desktop.
The Ruby method "alphabetize" sorts an array in alphabetical order. If you wish put true as second argument to sort in descending order.
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.reverse | |
else | |
arr.sort | |
end | |
end | |
puts alphabetize ["b","e","a"], true | |
# => ["e","b","a"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment