Open mayyaannkk opened 1 year ago
I believe this is intentional to show how default upper and lower bounds are changing while slicing. I may be wrong.
It might be but it did confuse me. I missed that it was overriding the slice and it made me think about how that output was even possible.
Context: https://go.dev/tour/moretypes/10
In the description, it was defined correctly that "default is zero for the low bound and the length of the slice for the high bound" and the examples were also correct. But in the given code we are updating the values of our original array
Output:
This does not work as expected as each time s is updated to point to new values, after
s = s[1:4]
new array (or slice) becomes[3, 5, 7]
and the next computation ofs = s[:2]
will be formed from this array only, giving us unexpected results.The correct code will look something like this:
Output: