j
Size: a a a
j
O
ДУ
IS
IS
K
ДУ
j
{
const str = 'BBBYHKIIIPPDDDDDDXXWWWWWWXADFGJJJJ';
const countRepeat = str => {
const repeat = {}
let result = ''
let i = 1
for (const char of str) {
if (str[i] === char) {
repeat[char] = repeat[char] + 1 || 1
} else {
if (repeat[char]) {
result += `${char}${repeat[char]}`
delete repeat[char]
} else {
result += char
}
}
i++
}
return result
}
console.log(countRepeat(str))
// B2YHKI2P1D5X1W5XADFGJ3
O
K
IS
O
{
j
O
j
j