Delete the Repeats


If you're viewing this on the Challenge Zone website, you can click here to open the challenge in a new tab.

Scenario

A new app has been developed that recongizes words containing repeated characters that are adjacent to each other. This app automatically detects these repeated characters and instantly deletes them from the word, creating new interesting words.


Task

Given a String containing characters from the alphabet [a-z, A-Z], write an alterCharacters function to delete all repeating characters that are adjacent to each other and return the total number of deleted characters.


function alterCharacters

The alterCharacters function should accept a String argument and return an Integer value.


Sample Results

alterCharacters("AAABB") // --> 3 alterCharacters("BBB") // --> 2 alterCharacters("ZZZSSS") // --> 4 alterCharacters("CHASE") // --> 0 alterCharacters("AllStarCode") // --> 1 alterCharacters("LittleRedRidingHood") // --> 2 alterCharacters("") // --> 0

Your function should work for any String argument. DO NOT HARDCODE!