mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
Add Filter (in place)
parent
99bf2690f9
commit
2f2dcdeec7
@ -69,6 +69,19 @@ a = append(a[:i], append(make([]T, j), a[i:]...)...)
|
|||||||
a = append(a, make([]T, j)...)
|
a = append(a, make([]T, j)...)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Filter (in place)
|
||||||
|
|
||||||
|
```go
|
||||||
|
n := 0
|
||||||
|
for _, x := range a {
|
||||||
|
if keep(x) {
|
||||||
|
a[n] = x
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a = a[:n]
|
||||||
|
```
|
||||||
|
|
||||||
#### Insert
|
#### Insert
|
||||||
```go
|
```go
|
||||||
a = append(a[:i], append([]T{x}, a[i:]...)...)
|
a = append(a[:i], append([]T{x}, a[i:]...)...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user