Files
lo/docs/data/core-maxindexby.md
T

997 B

name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory playUrl variantHelpers similarHelpers position signatures
MaxIndexBy maxindexby find.go#L482 core find https://go.dev/play/p/uaUszc-c9QK
core#find#maxindexby
core#find#max
core#find#maxby
core#find#maxindex
core#find#min
core#find#minby
core#find#minindex
core#find#minindexby
core#math#sum
core#math#mean
core#math#product
core#math#mode
230
func MaxIndexBy[T any](collection []T, comparison func(a T, b T) bool) (T, int)

Returns the maximum value and its index using the given comparison function. Returns (zero value, -1) when the collection is empty.

type Point struct{ X int }
value, idx := lo.MaxIndexBy([]Point{{1}, {5}, {3}}, func(a, b Point) bool {
    return a.X > b.X
})
// value == {5}, idx == 1

Note: the comparison function is inconsistent with most languages, since we use the opposite of the usual convention.

See https://github.com/samber/lo/issues/129