Skip to content

Commit

Permalink
fix DropRight limits condition
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Apr 18, 2022
1 parent 1dbdfc2 commit 6c19890
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Drop[T any](collection []T, n int) []T {
return result
}

//DropWhile drops elements from the beginning of a slice or array while the predicate returns true.
// DropWhile drops elements from the beginning of a slice or array while the predicate returns true.
func DropWhile[T any](collection []T, predicate func(T) bool) []T {
i := 0
for ; i < len(collection); i++ {
Expand All @@ -39,7 +39,7 @@ func DropRight[T any](collection []T, n int) []T {
}

result := make([]T, len(collection)-n)
for i := len(collection) - 1 - n; i != 0; i-- {
for i := len(collection) - 1 - n; i >= 0; i-- {
result[i] = collection[i]
}

Expand Down

0 comments on commit 6c19890

Please sign in to comment.