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

feat: add ReduceRight

This commit is contained in:
dudaodong
2023-04-04 17:54:54 +08:00
parent f198191063
commit c01c9d14b4
5 changed files with 95 additions and 3 deletions

View File

@@ -406,7 +406,7 @@ func TestReduce(t *testing.T) {
}
func TestReduceBy(t *testing.T) {
assert := internal.NewAssert(t, "TestReduce2")
assert := internal.NewAssert(t, "TestReduceBy")
result1 := ReduceBy([]int{1, 2, 3, 4}, 0, func(_ int, item int, agg int) int {
return agg + item
@@ -421,6 +421,16 @@ func TestReduceBy(t *testing.T) {
}
func TestReduceRight(t *testing.T) {
assert := internal.NewAssert(t, "ReduceRight")
result := ReduceRight([]int{1, 2, 3, 4}, "", func(_ int, item int, agg string) string {
return agg + fmt.Sprintf("%v", item)
})
assert.Equal("4321", result)
}
func TestIntSlice(t *testing.T) {
var nums []any
nums = append(nums, 1, 2, 3)