Skip to content

Instantly share code, notes, and snippets.

@lukewendling
Created January 28, 2013 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukewendling/4652972 to your computer and use it in GitHub Desktop.
Save lukewendling/4652972 to your computer and use it in GitHub Desktop.
def combine_anagrams(words)
h = {}
words.map do |word|
sort_key = word.each_char.sort.join
h[sort_key] ||= []
h[sort_key] << word
end
h.values
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment