[ create a new paste ] login | about

Link: http://codepad.org/tyixWRzh    [ raw code | output | fork ]

Ruby, pasted on Mar 3:
1
2
3
4
5
6
7
8
9
10
11
# 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:
1
2
nil
expected [["cars", "racs", "scar"], ["four"], ["for"], ["potatoes"], ["creams", "scream"]]


Create a new paste based on this one


Comments: