blob: 89ba67b8ad22585b1dc24b4ba7a4de172110f43e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
const std = @import("std");
const math = std.math;
/// Returns the position of the smallest number in a slice.
pub fn min_idx(comptime T: type, slice: []const T) usize {
var best = slice[0];
var idx: usize = 0;
for (slice[1..]) |item, i| {
const possible_best = math.min(best, item);
if (best > possible_best) {
best = possible_best;
idx = i + 1;
}
}
return idx;
}
|