Skip to content

Instantly share code, notes, and snippets.

@ph3nx
Last active June 28, 2018 02:26
Show Gist options
  • Save ph3nx/8510875 to your computer and use it in GitHub Desktop.
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.
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