Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by ZAA ( 13 years ago )
def combine_anagrams(words)
  
  return nil if(words == [])
  result = []
  for i in 0 .. words.length-1
    array = []
    for j in 0 .. words.length-1
      array << words[j] if(words[i].split("").sort.join.downcase == words[j].split("").sort.join.downcase)
    end
    result << array
  end
  
  return result.uniq!
end

ex = ['cars', 'for', 'potatoes', 'racs', 'four', 'scar', 'creams', 'scream'] 
puts combine_anagrams(ex)

 

Revise this Paste

Your Name: Code Language: