Function min [src]

Returns the smallest number in a slice. O(n). slice must not be empty.

Prototype

pub fn min(comptime T: type, slice: []const T) T

Parameters

T: typeslice: []const T

Example

test min { try testing.expectEqual(min(u8, "abcdefg"), 'a'); try testing.expectEqual(min(u8, "bcdefga"), 'a'); try testing.expectEqual(min(u8, "a"), 'a'); }

Source

pub fn min(comptime T: type, slice: []const T) T { assert(slice.len > 0); var best = slice[0]; for (slice[1..]) |item| { best = @min(best, item); } return best; }