mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(slice): pass actual comparison indexes to DifferenceBy (#370)
This commit is contained in:
1 parent
59cd9bd06f
commit
34c7e36d29
2 files changed
+5
-2
No files matched your search
+2
-2
@@ -187,8 +187,8 @@ func DifferenceBy[T comparable](slice []T, comparedSlice []T, iteratee func(inde
|
||||
result := make([]T, 0)
|
||||
|
||||
comparedMap := make(map[T]struct{}, len(comparedSlice))
|
||||
for _, item := range comparedSlice {
|
||||
comparedMap[iteratee(0, item)] = struct{}{}
|
||||
for i, item := range comparedSlice {
|
||||
comparedMap[iteratee(i, item)] = struct{}{}
|
||||
}
|
||||
|
||||
for i, item := range slice {
|
||||
|
||||
@@ -1205,6 +1205,9 @@ func TestDifferenceBy(t *testing.T) {
|
||||
}
|
||||
|
||||
assert.Equal([]int{1, 2}, DifferenceBy(s1, s2, addOne))
|
||||
assert.Equal([]int{}, DifferenceBy([]int{10, 10}, []int{10, 10}, func(i, v int) int {
|
||||
return i + v
|
||||
}))
|
||||
}
|
||||
|
||||
func TestIsAscending(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user