What you're building
A groupAnagrams(words) function that takes an array of strings and returns an
array of groups, where each group contains words that are anagrams of each other.
Requirements
- Two words are anagrams when they contain the same letters in any order
(e.g.
"listen"and"silent","eat"and"tea"). - Comparison is case-insensitive; store original casing in the output.
- Each group is an array of strings. The order of groups and the order within each group do not matter for the tests.
- Words that share no anagram partners appear in a group of their own.
Stretch goals
- Accept a second argument
minSizeand omit groups smaller than that. - Handle multi-word phrases (sort letters ignoring spaces).
What this proves
You can derive a canonical key from data (sorted characters), use it as a hash-map key to bucket items, and return structured grouped output — a pattern that appears in database grouping, file deduplication, and compiler symbol tables.
⚡ 50 XP
solution.jsRuns in your browser
Loading editor…
Tests3 to pass
groups basic anagrams
solo words form their own group
single word input
Run your code to check these.