Skip to content

Commit

Permalink
Merge branch 'master' of github.com:samber/lo
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Mar 3, 2022
2 parents 0a9b671 + 3c7e203 commit a10aa3e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions find.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ func Find[T any](collection []T, predicate func(T) bool) (T, bool) {
func Min[T constraints.Ordered](collection []T) T {
var min T

for i := 0; i < len(collection); i++ {
item := collection[i]
if len(collection) == 0 {
return min
}

if i == 0 {
min = item
continue
}
min = collection[0]

for i := 1; i < len(collection); i++ {
item := collection[i]

// if item.Less(min) {
if item < min {
Expand All @@ -71,13 +72,14 @@ func Min[T constraints.Ordered](collection []T) T {
func Max[T constraints.Ordered](collection []T) T {
var max T

for i := 0; i < len(collection); i++ {
item := collection[i]
if len(collection) == 0 {
return max
}

if i == 0 {
max = item
continue
}
max = collection[0]

for i := 1; i < len(collection); i++ {
item := collection[i]

if item > max {
max = item
Expand Down

0 comments on commit a10aa3e

Please sign in to comment.