Strings·hard 30 min 120 XP
String Compression
Compress consecutive repeated characters, e.g. 'aaabcc' → 'a3b1c2'. Only compress runs of length 1+.
Examples
- stringCompress("aaabcc") → "a3b1c2"
- stringCompress("abc") → "a1b1c1"
Constraints
- Keep the required function name so the tests can find it
- Return a value instead of only logging it
- Do not mutate inputs unless the challenge asks you to
String Compression · editor
Code runs in an isolated Web Worker with a 3-second timeout — no DOM access, and it can never hang the page.