1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize {
6 var found: usize = 0;
7 for (haystack) |item| {
8 if (item == needle) {
9 found += 1;
10 }
11 }
12 return found;
13}
14
15test {
16 try std.testing.expect(countScalar(u8, "The lazy brown fox jumped over the lazy dog.", ' ') == 8);
17}
18test {
19 try std.testing.expect(countScalar(u8, "kljsklksldajvaskidjklvadv", 'z') == 0);
20}