mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
Ordered delete's check for i<len(a)-1
is unnecessary. Slicing an n-length array using [n:]
will return an empty array, and so the copy will do nothing.
parent
0764ddec46
commit
7f4b67adb2
@ -47,9 +47,7 @@ a = a[:len(a)-j+i]
|
|||||||
|
|
||||||
> **Delete**
|
> **Delete**
|
||||||
```go
|
```go
|
||||||
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[len(a)-1] = nil // or the zero value of T
|
||||||
a = a[:len(a)-1]
|
a = a[:len(a)-1]
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user