All problems

Mosaic sample previews split some characters into broken labels

Level 1 · node · API · String truncation error at Unicode code point boundaries

Scenario

A fictional mosaic workshop creates short names for its sample list. Ordinary English and Korean names display correctly, but names containing certain musical symbols or supplementary-plane characters appear broken or shorter than expected under the same display limit. Review the label truncation function and the list response.

Requirements

preview(samples, limit) receives each sample's id and label and returns a list of {id, label} objects in input order. Each returned label must contain the first limit Unicode code points of the original name. limit is a nonnegative integer and input strings are valid Unicode. Count code points rather than user-perceived characters (grapheme clusters). Return names shorter than the limit unchanged and do not mutate the input.

Acceptance criteria

  • Return ordinary English and Korean names and names within the limit correctly.
  • Return the specified number of intact code points even when names contain supplementary-plane characters.
  • Return an empty string when the limit is zero or the name is empty.
  • Preserve sample identifiers and input order without modifying the original array or its entries.