I would like to remove an element from the slice in place. But when I do this I end up producing two empty elements in the underlying array. I already searched here, here
package main
import "fmt"
//String remove adjacent duplicates from a string array
func rmDup(str []string) []string {
for i := 1; i < len(str); i++ {
if str[i] == str[i-1] {
copy(str[i:], str[i+1:])
str[len(str)-1] = ""
str = str[:len(str)-1]
}
}
return str
}
func main() {
str := []string{"dog", "cat", "cat", "mouse", "mouse", "zebra", "zebra"}
fmt.Println(str)
newstr := rmDup(str)
fmt.Println(str)
fmt.Println(newstr)
fmt.Println(len(str), cap(str), "final")
fmt.Println(len(newstr), cap(newstr), "final")
}
Is there any way that str in main can return the size and capacity defined in rmDup()