- Sort Score
- Result 10 results
- Languages All
Results 1 - 2 of 2 for SliceMax (0.14 sec)
-
test/typeparam/sliceimp.dir/main.go
func TestMax() { s1 := []int{1, 2, 3, -5} if got, want := a.SliceMax(s1), 3; got != want { panic(fmt.Sprintf("a.Max(%v) = %d, want %d", s1, got, want)) } s2 := []string{"aaa", "a", "aa", "aaaa"} if got, want := a.SliceMax(s2), "aaaa"; got != want { panic(fmt.Sprintf("a.Max(%v) = %q, want %q", s2, got, want)) } if got, want := a.SliceMax(s2[:0]), ""; got != want {
Registered: Wed Jun 12 16:32:35 UTC 2024 - Last Modified: Thu Mar 24 02:14:15 UTC 2022 - 4.6K bytes - Viewed (0) -
test/typeparam/sliceimp.dir/a.go
if f(v) { r = append(r, v) } } return r } // Max returns the maximum element in a slice of some ordered type. // If the slice is empty it returns the zero value of the element type. func SliceMax[Elem Ordered](s []Elem) Elem { if len(s) == 0 { var zero Elem return zero } return Reduce(s[1:], s[0], Max[Elem]) } // Min returns the minimum element in a slice of some ordered type.
Registered: Wed Jun 12 16:32:35 UTC 2024 - Last Modified: Mon Aug 30 01:55:58 UTC 2021 - 3.3K bytes - Viewed (0)