Created
April 25, 2018 13:32
-
-
Save arehmandev/b081d50bf7def5d8660aa706c3410110 to your computer and use it in GitHub Desktop.
Iteratively remove elements from slice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
slice := []string{"TEST1", "TEST2", "TEST3", "TEST4"} | |
fmt.Println("SLICE AT START", slice) | |
for i := len(slice) - 1; i >= 0; i-- { | |
fmt.Println("REMOVE FROM ARRAY:", slice[i]) | |
slice = append(slice[:i], slice[i+1:]...) | |
fmt.Println("SLICE:", slice) | |
} | |
fmt.Println("SLICE AT END", slice) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment