Created
September 29, 2012 11:41
-
-
Save vindia/3803755 to your computer and use it in GitHub Desktop.
OCDify (set all letters in a word in the correct order)
This file contains hidden or 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
# Order all letters in a word in a string | |
# | |
# Examples: | |
# | |
# ocdify('What is the point of this') | |
# # => 'ahtw is eht inopt fo hist' | |
# | |
# Returns the ordered String | |
def ocdify(string) | |
a = [] | |
string.downcase.split.each do |word| | |
a << word.split('').sort.join('') | |
end | |
a.join(' ') | |
end | |
puts ocdify('What is the point of this') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment