Function argmax

Source
pub fn argmax<I: IntoIterator>(iter: I) -> Option<usize>
where I::Item: PartialOrd + Copy,
Expand description

Returns the index of the maximum value in an iterator, or None if the iterator is empty.

If the maximum appears several times, this methods returns the position of the first instance.

§Arguments

  • iter: the iterator.

§Panics

If a comparison returns None.

§Examples

let v = vec![1, 2, 5, 2, 1, 5];
let index = argmax(&v);
assert_eq!(index, Some(2));