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 authored and GitHub committed 2022-07-21 15:19:18 +08:00
1 parent ac0fb5ef25
commit a82b5dd206
4 files changed
+61 -3

No files matched your search

+17
View File
@@ -36,6 +36,23 @@ func TestIndexOf(t *testing.T) {
assert.Equal(-1, i)
}
func TestLastIndexOf(t *testing.T) {
assert := internal.NewAssert(t, "TestIndexOf")
list := NewList([]int{1, 2, 3, 3, 3, 3, 4, 5, 6, 9})
i := list.LastIndexOf(3)
assert.Equal(5, i)
i = list.LastIndexOf(10)
assert.Equal(-1, i)
i = list.LastIndexOf(4)
assert.Equal(6, i)
i = list.LastIndexOf(1)
assert.Equal(0, i)
}
func TestContain(t *testing.T) {
assert := internal.NewAssert(t, "TestContain")