In my game I am populating an array with one of several strings based on player input. I would like to count the number of occurrences of the string in the array, but only if those occurrences are next to each other in the array. E.g. if I'm counting the number of occurrences of "cat" in my array the following should be returned:
("cat", "dog", "cat", "dog") - should only return a count of 1 as the two occurrences of "cat" are separated by dog
("cat", "cat", "dog", "cat") - should return a count of 2
("cat", "cat", "cat", "dog") - should return a count of 3
Any suggestions/pointers appreciated.