Here's the two-pointer approach. The read pointer moves through groups while the write pointer overwrites in-place. When a count exceeds digit, you convert it to a string and write each digit separately.
function compress(chars):
write = 0
read = 0
while read < chars.length:
currentChar = chars[read]
count = 0
while read < chars.length and chars[read] == currentChar:
read += 1
count += 1
chars[write] = currentChar
write += 1
if count > 1:
for digit in str(count):
chars[write] = digit
write += 1
return write