Skip to content

Commit 03e8d81

Browse files
committed
Refactor out loop into it's own naughty word function
1 parent 86849b2 commit 03e8d81

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ fn main() -> Result<(), Box<std::error::Error>> {
2121
for curse in &curses {
2222
occurrences.entry(curse.to_string()).or_insert(0);
2323
}
24-
for word in "this is a fucking shit sentence with no goddamn shite in it".split(' ') {
25-
if curses.contains(&word) {
24+
for word in "this is a fucking shit sentence with no goddamn shite in it".split_whitespace() {
25+
if naughty_word(&word, &curses) {
2626
occurrences.entry(word.to_string()).and_modify(|i| *i += 1);
2727
}
2828
}
@@ -34,3 +34,10 @@ fn main() -> Result<(), Box<std::error::Error>> {
3434
println!("{:#?}", occurrences);
3535
Ok(())
3636
}
37+
38+
fn naughty_word(word: &str, naughty_list: &Vec<&str>) -> bool {
39+
if naughty_list.contains(&word) {
40+
return true;
41+
}
42+
false
43+
}

0 commit comments

Comments
 (0)