```
/** The words grouped by their length, in first-seen order. */
export function groupByLength(words: readonly string[]): Map<number, readonly string[]> {
  const groups = new Map;
  for (const word of words) {
    const bucket = groups.get(word.length);
    if (!bucket || bucket.length === 0) {
      groups.set(word.length, [word]);
    } else {
      bucket.push(word);
      // Ensure the resulting array is a read-only view
      groups.set(word.length, [...(groups.get(word.length)!)]);
    }
  }
  return groups;
}
```