Or, how about this one?
func FirstSubsliceWithoutAdjacentDuplicates(strings []string) ([]string, int) {
if len(strings) < 2 {
return strings, 0
}
for i := 1; i < len(strings); i++ {
if strings[i-1] == strings[i] {
repeats := 1
for i+repeats < len(strings) && strings[i] == strings[i+repeats] {
repeats++
}
return strings[:i], repeats
}
}
return strings, 0
}
func RemoveAdjacentDuplicates(toBeProcessed []string) []string {
unique, repeats := FirstSubsliceWithoutAdjacentDuplicates(toBeProcessed)
if len(unique) == len(toBeProcessed) {
return unique
}
result := toBeProcessed
copyTarget := toBeProcessed
finalLength := 0
for len(unique) > 0 {
finalLength += len(unique)
copy(copyTarget, unique)
toBeProcessed = toBeProcessed[len(unique)+repeats:]
copyTarget = copyTarget[len(unique):]
unique, repeats = FirstSubsliceWithoutAdjacentDuplicates(toBeProcessed)
}
return result[0:finalLength]
}