Skip to content

Instantly share code, notes, and snippets.

@locks
Created October 18, 2014 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save locks/5c76122b0bbe0f3f0d75 to your computer and use it in GitHub Desktop.
Save locks/5c76122b0bbe0f3f0d75 to your computer and use it in GitHub Desktop.
Solution to Bob
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