..  minmax(x, y)

Return ``(min(x,y), max(x,y))``.
See also: :func:`extrema` that returns ``(minimum(x), maximum(x))``


The minmax function in Julia returns a tuple containing the minimum and maximum of two given values, x and y.

julia> minmax(4, 7)
(4, 7)

This example returns a tuple (4, 7) where the first element is the minimum value (4) and the second element is the maximum value (7).

julia> minmax(10.5, 8.2)
(8.2, 10.5)

In this example, the minmax function is used with floating-point values, returning a tuple (8.2, 10.5) where 8.2 is the minimum value and 10.5 is the maximum value.

julia> minmax("apple", "banana")
("apple", "banana")

The minmax function can also be used with strings. In this case, it returns a tuple ("apple", "banana") where "apple" is the minimum value (lexicographically) and "banana" is the maximum value.

julia> a = 5
       b = 3
       min_val, max_val = minmax(a, b)
       println(min_val, ", ", max_val)

You can assign the returned values to separate variables (min_val and max_val) using tuple unpacking. In this example, it will print 3, 5.

Note: The minmax function is typically used to quickly find both the minimum and maximum of two values. If you want to find the minimum and maximum of an array or collection, you can use the extrema function instead.

See Also

cummax, eigmax, findmax, hist, hist!, hist2d, hist2d!, histrange, indmax, maxabs, maxabs!, maximum!, mean, mean!, median, median!, minabs, minabs!, minimum!, minmax, quantile!, realmax, std, stdm,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: