Hi,
I’m doing codewars tasks. I have to write function that returns the count of characters that have to be removed in order to get a string with no consecutive repeats.
Examples:
'abbbbc' => 'abc' # answer: 3
'abbcca' => 'abc' # answer: 2
'ab cca' => 'ab ca' # answer: 1
What I have done wrong here?
Below is my code:
function countRepeats(str) {
// return str; // the whole string
let unique = String.prototype.concat(...new Set(str));
// return unique.length;
// return str.length;
let diff = str.length - unique.length; // should be 6 - 4 = 2
return diff;
}