Use mem.eql for dictionary test
This commit is contained in:
+2
-12
@@ -62,18 +62,8 @@ fn loadDict() []const Wordle.Word {
|
||||
// TODO: binary search? need to assert that words are sorted
|
||||
pub fn isInDictionary(word: Wordle.Word) bool {
|
||||
// exhaustively search through dictionary
|
||||
for (getDictionary()) |entry| {
|
||||
// compare each letter at a time
|
||||
var match = true;
|
||||
for (entry, word) |entryLetter, wordLetter| {
|
||||
if (entryLetter != wordLetter) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if every letter matches, return a complete match
|
||||
if (match) {
|
||||
for (getDictionary()) |*entry| {
|
||||
if (std.mem.eql(u8, entry, &word)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user