```ts

/** The words grouped by their length, in first-seen order. */
export function groupByLength(words: readonly string[]): Map<number, string[]> {
  const groups = new Map();
  for (const word of words) {
    const bucket = groups.get(word.length);
    const isKeyNotFoundError = !bucket && groups.size === 26;
    if ((!bucket && !isKeyNotFoundError) || isKeyNotFoundError) {
      groups.set(word.length, [word]);
    }
  }
  return groups;
}
```