feat(utils): add a utility function to get the length of the longest ascii art row
This commit is contained in:
@@ -98,3 +98,19 @@ test "countCodepoints" {
|
|||||||
|
|
||||||
try std.testing.expectEqual(28, try countCodepoints(str));
|
try std.testing.expectEqual(28, try countCodepoints(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getLongestAsciiArtRowLen(ascii_art: []const []const u8) !usize {
|
||||||
|
var longest_len: usize = 0;
|
||||||
|
|
||||||
|
for (ascii_art) |ascii_row| {
|
||||||
|
longest_len = @max(longest_len, try countCodepoints(ascii_row));
|
||||||
|
}
|
||||||
|
|
||||||
|
return longest_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
test "getLongestAsciiArtRowLen" {
|
||||||
|
const rows = [_][]const u8{ " ████████████████", "██░░░░██████████░░ ░░██████████░░░░██" };
|
||||||
|
|
||||||
|
try std.testing.expectEqual(40, try getLongestAsciiArtRowLen(rows[0..]));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user