score:1

Accepted answer

getGroupedAnagrams(words: string[]) {
    const anagrams = {} as any;
    words.forEach((word) => {
      const sortedWord = this.alphabetize(word);
      if (sortedWord) {
        if( anagrams[sortedWord]){
          return anagrams[sortedWord].push(word); 
        }
        anagrams[sortedWord] = [word];
      } 
    });
    return anagrams;
  }

Related Query

More Query from same tag