Last active
August 12, 2021 07:06
-
-
Save linw1995/7165a87794c94f983798b391ad4e8fa5 to your computer and use it in GitHub Desktop.
Golang Troublesome problem
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
// https://play.golang.org/p/bxTn8L2gf3d | |
package main | |
import ( | |
"fmt" | |
) | |
func Remove(arr []int, idx int) (rv []int) { | |
rv = arr[:idx] | |
rv = append(rv, arr[idx+1:]...) | |
return rv | |
} | |
func main() { | |
arr := [...]int{0, 1, 2, 3, 4, 5, 6} | |
fmt.Println(arr, Remove(arr[:], 1)) | |
// [0 1 2 3 4 5 6] [0 2 3 4 5 6] | |
slic := []int{0, 1, 2, 3, 4, 5, 6} | |
fmt.Println(slic, Remove(slic, 1)) | |
// [0 2 3 4 5 6 6] [0 2 3 4 5 6] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment