JSFiddle - React, Tailwind, and code Playground
by krustnic
JavaScript
let s = "AAAAAAAABBBBBCCCCCDDDDXYZ"
function f(s) {
return s.match(/(.)\1*/g).reduce((out, item) => {
out += item[0] + (item.length === 1 ? '' : item.length)
return out
}, '')
}
console.log(f(s))