bugger.
All challenges/JavaScriptmediumthe-name-that-counts-twice-v1
THE INVESTIGATION

The name that counts twice

A profile validator counts one supplementary character twice and cuts its preview in half.

JavaScriptRepresentation invariantsRegression testing

What’s going wrong

Input is a JSON array of at most 100 objects {text, min, max, preview}. text is a well-formed UTF-16 string with at most 1000 code units; unpaired surrogates are excluded. The integer bounds satisfy 0 <= min <= max <= 1000 and 0 <= preview <= 1000. Define length as the number of Unicode code points, not UTF-16 code units, UTF-8 bytes or displayed grapheme clusters. Combining marks, variation selectors and zero-width joiners each count as their own code point. Return {length, valid, preview} for every row, where valid uses inclusive min/max and preview is the first preview code points (possibly empty or the entire string). Preserve all original code points and do not normalize text.

Expected behavior

Keep validation and preview slicing consistent with a declared Unicode counting unit.

Reproduction

01 Supplementary name
[{"text":"A\ud83d\ude00B","min":3,"max":3,"preview":2}]
[{"length":3,"valid":true,"preview":"A\ud83d\ude00"}]
02 ASCII control
[{"text":"Ada","min":2,"max":4,"preview":2}]
[{"length":3,"valid":true,"preview":"Ad"}]
03 Empty control
[{"text":"","min":0,"max":0,"preview":0}]
[{"length":0,"valid":true,"preview":""}]

Before you begin

  • JavaScript functions, arrays and objects
  • Transfer numeric normalization discipline to the difference between storage units and product units.

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.