Ruby,
pasted
on Mar 3:
|
# input: ['cars', 'for', 'potatoes', 'racs', 'four','scar', 'creams', 'scream']
# => output: [["cars", "racs", "scar"], ["four"], ["for"], ["potatoes"], ["creams", "scream"]]
# HINT: you can quickly tell if two words are anagrams by sorting their
# letters, keeping in mind that upper vs lowercase doesn't matter
def combine_anagrams(words)
# your code here
end
words = ['cars', 'for', 'potatoes', 'racs', 'four','scar', 'creams', 'scream']
puts combine_anagrams(words).inspect
puts 'expected [["cars", "racs", "scar"], ["four"], ["for"], ["potatoes"], ["creams", "scream"]]'
|
Output:
|
nil
expected [["cars", "racs", "scar"], ["four"], ["for"], ["potatoes"], ["creams", "scream"]]
|
|