mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
fix: do not delete last element if target index is out of range
parent
5913902828
commit
daccf419a0
@ -49,9 +49,9 @@ a = a[:len(a)-j+i]
|
|||||||
```go
|
```go
|
||||||
if i < len(a)-1 {
|
if i < len(a)-1 {
|
||||||
copy(a[i:], a[i+1:])
|
copy(a[i:], a[i+1:])
|
||||||
|
a[len(a)-1] = nil // or the zero value of T
|
||||||
|
a = a[:len(a)-1]
|
||||||
}
|
}
|
||||||
a[len(a)-1] = nil // or the zero value of T
|
|
||||||
a = a[:len(a)-1]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Delete without preserving order**
|
> **Delete without preserving order**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user