Skip to content

Instantly share code, notes, and snippets.

@alxfv
Last active December 11, 2015 15:18
Show Gist options
  • Select an option

  • Save alxfv/4619894 to your computer and use it in GitHub Desktop.

Select an option

Save alxfv/4619894 to your computer and use it in GitHub Desktop.
def combine_anagrams(words)
output = {}
words.each do |word|
index = word.downcase.chars.sort.join
output[index].is_a?(Array) ? output[index] << word : output[index] = [word]
end
output.values
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment