1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 16:22:26 +08:00

fix: The LastIndexOf method can never return the index of the first element (#83)

Co-authored-by: JiangCheng <jiangcheng@kezaihui.com>
This commit is contained in:
Mickls
2023-03-28 20:02:57 +08:00
committed by GitHub
parent f09e521783
commit 3b497532f3
2 changed files with 6 additions and 5 deletions

View File

@@ -1094,7 +1094,7 @@ func IndexOf[T comparable](arr []T, val T) int {
// LastIndexOf returns the index at which the last occurrence of the item is found in a slice or return -1 if the then cannot be found.
// Play: https://go.dev/play/p/DokM4cf1IKH
func LastIndexOf[T comparable](slice []T, item T) int {
for i := len(slice) - 1; i > 0; i-- {
for i := len(slice) - 1; i >= 0; i-- {
if item == slice[i] {
return i
}