Go Slice question, please check below and comment if I am missing something.
import "fmt"
func main() {
s := []int{2, 3, 5, 7, 11, 13}
s = s[1:]
fmt.Println(s)
s = s[2:]
fmt.Println(s)
s = s[5:]
fmt.Println(s)
}
Output:
[3 5 7 11 13]
[7 11 13]
panic: runtime error: slice bounds out of range
The above makes sense.
func main() {
s := []int{2, 3, 5, 7, 11, 13}
s = s[:1]
fmt.Println(s)
s = s[:2]
fmt.Println(s)
s = s[:5]
fmt.Println(s)
}
Output:
[2]
[2 3]
[2 3 5 7 11]
Should this also get array out of bounds panic from s=s[:2]?