Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@linw1995
Last active August 12, 2021 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linw1995/7165a87794c94f983798b391ad4e8fa5 to your computer and use it in GitHub Desktop.
Save linw1995/7165a87794c94f983798b391ad4e8fa5 to your computer and use it in GitHub Desktop.
Golang Troublesome problem
// 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