Code RoomSurrogate pair breaks character count
MediumPrep Room Coding #1965

Surrogate pair breaks character count

Code reviewCode quality & reviewMid–Senior~18 min

Review this JavaScript that enforces a 280-'character' post limit, hard-caps the text, and reports how many characters remain.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 18 min
Mark a line and say what kind of problem it is.0 findings
1const MAX = 280;
2 
3function enforceLimit(text) {
4 if (text.length > MAX) {
5 text = text.slice(0, MAX); // hard cap to fit
6 }
7 return {
8 text,
9 remaining: MAX - text.length,
10 overLimit: text.length > MAX,
11 };
12}
13 
14// enforceLimit('\uD83D\uDE00'.repeat(200))
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.