You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code for default indexing on slices actually does not illustrate the default beginning and end indices well. As per the code,
s := []int{2, 3, 5, 7, 11, 13}
s = s[1:4]
s = s[:2]
s = s[1:]
which prints
[3 5 7]
[3 5]
[5]
Here, the slicing for the second and third time applies on the updated slice and not the original one. While the output is correct, a better approach, as far as explanation is concerned, might be to create a new slice, store the original slice's in it and display it. For example,
s := []int{2, 3, 5, 7, 11, 13}
t := s[1:4]
t = s[:2]
t = s[1:]
which prints
[3 5 7]
[2 3]
[3 5 7 11 13]
might be the code that illustrates the concepts better.
The text was updated successfully, but these errors were encountered:
Context: https://go.dev/tour/moretypes/10
The code for default indexing on slices actually does not illustrate the default beginning and end indices well. As per the code,
which prints
Here, the slicing for the second and third time applies on the updated slice and not the original one. While the output is correct, a better approach, as far as explanation is concerned, might be to create a new slice, store the original slice's in it and display it. For example,
which prints
might be the code that illustrates the concepts better.
The text was updated successfully, but these errors were encountered: