Below code increments only ith element of that slice. Is there something inbuild that i can increment all elements with 1. Please suggest.
for i:= 0; i< k ;i++{
if(slice[i] < K){
slice[i] = slice[i] + 1
}
}
Below code increments only ith element of that slice. Is there something inbuild that i can increment all elements with 1. Please suggest.
for i:= 0; i< k ;i++{
if(slice[i] < K){
slice[i] = slice[i] + 1
}
}
While working with slices you will find that you will gravitate towards for
loops. Go doesn't have extra functions for slices that you might find with other languages.
for i := range slice {
slice[i]++
}