exercism/zig/isogram/isogram.zig

27 lines
548 B
Zig
Raw Permalink Normal View History

pub const std = @import("std");
pub fn cmp(context: void, a: u8, b: u8) bool {
_ = context;
if (a < b) {
return true;
}
return false;
}
pub fn isIsogram(str: []const u8) bool {
const len = str.len;
if (len == 0) return true;
var buf = [_]u8{0} ** 256;
const lower = std.ascii.lowerString(&buf, str);
std.mem.sort(u8, lower, {}, cmp);
for (0..len - 1) |i| {
if (lower[i] == lower[i + 1] and std.ascii.isAlphabetic(lower[i])) {
return false;
}
}
return true;
}