fun getAnagrams(words: Array): MutableList<ArrayList> {
var array: Array = Array(words.size) { WordWithIndex(words[it], it) }
array = wordArraySort(array)
val anagrams: MutableList<ArrayList> = ArrayList()
var i=0
while (i < array.size - 1) {
if (array[i].word == array[i + 1].word) {
val newGroup: MutableList = ArrayList()
newGroup.add(words[array[i].index])
newGroup.add(words[array[++i].index])
while (i < array.size - 1 && array[i].word == array[i + 1].word) {
i++
newGroup.add(words[array[i].index])
}
anagrams.add(newGroup as ArrayList)
}
i++
}
return anagrams
}