Loading exercise…

Caption poster studio

Complete the text layout behind a downloadable poster, including long words and explicit line breaks.

Task

Build a caption-layout feature that fits text into a fixed-width poster without overflowing its lines.

Requirements

  1. Return an array of lines, each at most columns characters. Columns must be an integer from 1 to 60; otherwise throw an Error.
  2. This renderer uses ASCII text in a fixed-width font: columns measures character cells, not proportional-font pixels.
  3. Collapse spaces and tabs within a paragraph. Preserve explicit newlines, including blank lines. Normalize Windows line endings.
  4. Place whole words where they fit. Split a word longer than columns into full-width chunks; its final chunk may share a line with the next word. Empty input returns [].

Exercises

AI-assisted Coding9 exercises