I implemented a function to group anagrams. In a nutshell:
input: [\'cars\', \'for\', \'potatoes\', \'racs\', \'four\',\'scar\', \'creams\', scream\']
output
You could use the partition
function instead of select, implemented in Enumerable. It splits the entries within the array according to the decision-function into two arrays.
def group_anagrams(words)
array = []
until words.empty?
word = words.first
delta, words = words.partition { |match| word.downcase.chars.sort.join.eql?(match.downcase.chars.sort.join ) } )
array += delta
end
array
end
(untested)