indmin

indmin(itr) -> Integer

Returns the index of the minimum element in a collection.

Examples

Find the index of the minimum element in an array:

julia> arr = [6, 2, 9, 1, 5];
julia> indmin(arr)
4

This example returns the index of the minimum element in the array arr, which is 4.

Find the index of the minimum element in a vector of strings:

julia> words = ["apple", "banana", "orange", "grape"];
julia> indmin(words)
2

It returns the index of the minimum element in the vector of strings words, which is 2.

Handle edge cases when the minimum element is at the first index:

julia> nums = [5, 8, 10];
julia> indmin(nums)
1

It correctly handles the case where the minimum element is at the first index.

Common mistake example:

julia> empty_arr = [];
julia> indmin(empty_arr)
ERROR: ArgumentError: collection must be non-empty

In this example, the function raises an error because the collection provided is empty. Ensure that the collection passed to indmin is non-empty to avoid such errors.

See Also

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
Details

Checking you are not a robot: