feat: add FindLastBy function

This commit is contained in:
dudaodong committed 2023-04-17 20:17:26 +08:00
1 parent 14bc08c6d6
commit 52ea64bc33
3 files changed
+56

No files matched your search

+19
View File
@@ -268,6 +268,25 @@ func TestFindBy(t *testing.T) {
assert.Equal(res == 0 && ok == false, true)
}
func TestFindLastBy(t *testing.T) {
assert := internal.NewAssert(t, "TestFindBy")
nums := []int{1, 2, 3, 4, 5}
even := func(i, num int) bool {
return num%2 == 0
}
res, ok := FindLastBy(nums, even)
if !ok {
t.Fatal("found nothing")
}
assert.Equal(4, res)
res, ok = FindLastBy(nums, func(_ int, v int) bool {
return v == 6
})
assert.Equal(res == 0 && ok == false, true)
}
func TestFindLast(t *testing.T) {
nums := []int{1, 2, 3, 4, 5}
even := func(i, num int) bool {