I have the input string "lorrem ipsssum dollorrrrum" and I want to count the same letter if the current letter is the same as the previous letter and change all the next same letter to the counted that letter,
I want the exact result to look like this:
"lor2emips3umdol2or4um"
I am stuck and I don't know what algorithm should I use, and what keyword to search about this issue in Google :(
The code I've written so far
function countLetter(str) {
return str
.replace(/\s/g, '')
.split('')
.reduce((a, b) => {
return a === b ? b.replace(b, '') : b;
});
}
window.onload = function () {
console.log(countLetter('lorrem ipsssum dollorrrrum'));
}