| ... | @@ -3,14 +3,12 @@ const string = []const u8; | ... | @@ -3,14 +3,12 @@ const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); | 3 | const extras = @import("./lib.zig"); |
| 4 | | 4 | |
| 5 | pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize { | 5 | pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize { |
| 6 | var i: usize = 0; | | |
| 7 | var found: usize = 0; | 6 | var found: usize = 0; |
| 8 | | 7 | for (haystack) |item| { |
| 9 | while (std.mem.indexOfScalarPos(T, haystack, i, needle)) |idx| { | 8 | if (item == needle) { |
| 10 | i = idx + 1; | 9 | found += 1; |
| 11 | found += 1; | 10 | } |
| 12 | } | 11 | } |
| 13 | | | |
| 14 | return found; | 12 | return found; |
| 15 | } | 13 | } |
| 16 | | 14 | |