Skip to content

Instantly share code, notes, and snippets.

@rjeczalik
Created May 20, 2014 19:01
Show Gist options
  • Save rjeczalik/e0571b9d0cead21159aa to your computer and use it in GitHub Desktop.
Save rjeczalik/e0571b9d0cead21159aa to your computer and use it in GitHub Desktop.
jobs-batch-remove.go
package main
import (
"fmt"
"sort"
)
type T string
func rm(t []T, idx []int) []T {
sort.IntSlice(idx).Sort()
for i, idx := range idx {
idx -= i
t = append(t[:idx], t[idx+1:]...)
}
return t
}
var t = []T{
0: "a",
1: "x",
2: "x",
3: "b",
4: "c",
5: "x",
6: "d",
7: "x",
8: "e",
9: "x",
}
var idx = []int{1, 2, 5, 7, 9}
func main() {
fmt.Println(rm(t, idx))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment