```
export function groupByLength(words: readonly string[]): Map<number, string[]> {
  const groups = new Map();
  for (const word of words) {
    if (!Array.isArray(groups.get(word.length))) {
      groups.set(word.length, [word]);
    } else {
      groups.get(word.length)?.push(word);
    }
  }
  return groups;
}
```