fix: add break to forbidden word loops to count each word only once in for_loops method
This commit is contained in:
@@ -58,8 +58,8 @@ impl Stats {
|
||||
return;
|
||||
};
|
||||
self.file_count += 1;
|
||||
self.muncher(&text);
|
||||
// self.for_loops(&text);
|
||||
// self.muncher(&text);
|
||||
self.for_loops(&text);
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
/// probably buggy. for example, are new lines sentences? what if the text has no last period?
|
||||
@@ -89,6 +89,7 @@ impl Stats {
|
||||
for forbidden_word in FORBIDDEN_WORDS {
|
||||
if lowercase_word.contains(forbidden_word) {
|
||||
self.forbidden_count += 1;
|
||||
break; //if you find one count it as a whole word
|
||||
}
|
||||
}
|
||||
word = String::new();
|
||||
@@ -113,6 +114,7 @@ impl Stats {
|
||||
for forbidden_word in FORBIDDEN_WORDS {
|
||||
if lowercase_word.contains(forbidden_word) {
|
||||
self.forbidden_count += 1;
|
||||
break; //if you find one count it as a whole word
|
||||
}
|
||||
}
|
||||
word = String::new();
|
||||
@@ -161,6 +163,7 @@ impl Stats {
|
||||
for forbidden_word in FORBIDDEN_WORDS {
|
||||
if lowercase_word.contains(forbidden_word) {
|
||||
self.forbidden_count += 1;
|
||||
break; //if you find one count it as a whole word
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user