1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 14:42:27 +08:00

list: add LastIndexOf (#46)

Add LastIndexOf method too List and fix doc

LastIndexOf returns the index of the last occurrence of the value in this list.
if not found return -1
This commit is contained in:
donutloop
2022-07-21 09:19:18 +02:00
committed by GitHub
parent ac0fb5ef25
commit a82b5dd206
4 changed files with 61 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ import (
- [Data](#Data)
- [ValueOf](#ValueOf)
- [IndexOf](#IndexOf)
- [LastIndexOf](#LastIndexOf)
- [Push](#Push)
- [PopFirst](#PopFirst)
- [PopLast](#PopLast)
@@ -167,7 +168,7 @@ func main() {
### <span id="IndexOf">IndexOf</span>
<p>Reture the index of value in the list. if not found return -1</p>
<p>Returns the index of value in the list. if not found return -1</p>
<b>Signature:</b>
@@ -192,6 +193,32 @@ func main() {
}
```
### <span id="LastIndexOf">LastIndexOf</span>
<p> Returns the index of the last occurrence of the value in this list if not found return -1</p>
<b>Signature:</b>
```go
func (l *List[T]) LastIndexOf(value T) int
```
<b>Example:</b>
```go
package main
import (
"fmt"
list "github.com/duke-git/lancet/v2/datastructure/list"
)
func main() {
li := list.NewList([]int{1, 2, 3, 1})
fmt.Println(li.LastIndexOf(1)) // 3
fmt.Println(li.LastIndexOf(0)) //-1
}
```
### <span id="Push">Push</span>

View File

@@ -27,7 +27,7 @@ import (
- [Merge](#Merge)
- [Minus](#Minus)
- [Values](#Values)
- [Values](#Values)
- [IsDisjoint](#IsDisjoint)
<div STYLE="page-break-after: always;"></div>