Created
October 18, 2014 12:25
-
-
Save locks/5c76122b0bbe0f3f0d75 to your computer and use it in GitHub Desktop.
Solution to Bob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Sentence { | |
Question, | |
Yelling, | |
Silence, | |
Generic | |
} | |
pub fn reply(message: &str) -> &str { | |
match sentence_type(message) { | |
Question => "Sure.", | |
Yelling => "Whoa, chill out!", | |
Silence => "Fine. Be that way!", | |
Generic => "Whatever." | |
} | |
} | |
fn sentence_type(message: &str) -> Sentence { | |
let trimmed_message = message.trim(); | |
if trimmed_message.is_empty() { return Silence; } | |
if trimmed_message.ends_with("?") { return Question; } | |
if trimmed_message.chars().all(|char| !char.is_lowercase()) { return Yelling; } | |
Generic | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment