codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
# 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"]]'
Private
[
?
]
Run code
Submit