Is there any way to use max() and min() based on a function?

You can also pass the function to argmax, to avoid the allocation of the intermediate array:

julia> x = [1,3,2]
3-element Vector{Int64}:
 1
 3
 2

julia> argmax(x -> -x^2, x)
1

julia> argmax(x -> x^2, x)
3


4 Likes