Is there a more idiomatic way of finding if some value is contained in an array than
fn valueInArray(value: u32, array: []const u32) bool {
for (array) |num| {
if (value == num) {
return true;
}
}
return false;
}
I think that this is generally the most idiomatic solution. It is possible to use
containsAtLeast
fromstd.mem
, but this seems like an abuse of that function (which is really for finding sequences):But I think that the OP posted code could be made more idiomatic by using
comptime
to allow it to accept types other thanu32
: