Advertisement
jctt

combine_anagrams

Feb 21st, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.18 KB | None | 0 0
  1. def combine_anagrams(words)
  2.     h = Hash[words.map {|x| [x.downcase.chars.sort.join, Array.new ]}]
  3.    
  4.     words.each { |x| h[x.downcase.chars.sort.join].push(x) }
  5.    
  6.     return h.values
  7. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement