sort an array of strings so that all the anagrams are next to each other