JSFiddle - React, Tailwind, and code Playground
HTML
count the no of occurances of each chararcter
JavaScript
function cntConsecutiveElements(array) {
let result = "";
let counter = 1;
for (let i = 0; i < array.length; i++) {
if (array[i] === array[i + 1]) {
counter++;
} else {
result += array[i] + counter;
counter = 1;
}
}
return result;
}
console.log(cntConsecutiveElements('aabbaaaccdddd'))