JavaScript Coding Challenge #10
Florin Pop
122

Hello,
Just to provide an alternative using RegExp. It can be improved because RegExp is not exactly the most performing solution.


function lineEncoding(s) {
 const reg = new RegExp(str.replace(/[a-z]{1}/g, m => `${m}{1,}|`).slice(0,-1), `g`);
 return s.replace(reg, m => `${m.length === 1 ? ‘’: m.length}${m.slice(-1)}`)
}