JSFiddle - React, Tailwind, and code Playground

by Scott Kaye

JavaScript

c=s=>s.match(/(.)\1*/g).map(m=>m.length>2?m[0]+m.length:m).join``;

console.clear();
console.log(c("aaaabbcccccd"));