pub fn findMin(comptime T: type, slice: []const T) usize T: typeslice: []const T3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822pub fn findMin(comptime T: type, slice: []const T) usize {
assert(slice.len > 0);
var best = slice[0];
var index: usize = 0;
for (slice[1..], 0..) |item, i| {
if (item < best) {
best = item;
index = i + 1;
}
}
return index;
}
Returns the index of the smallest number in a slice. O(n).
slicemust not be empty.