Skip to content

Instantly share code, notes, and snippets.

@lf94
Created October 23, 2017 17:51
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 lf94/1c8871c5efa739377d43f8db958037ce to your computer and use it in GitHub Desktop.
Save lf94/1c8871c5efa739377d43f8db958037ce to your computer and use it in GitHub Desktop.
pub fn reply(message: &str) -> &str {
let chrs = || message.trim().chars();
let has_text = chrs().any(|c| c.is_alphanumeric());
let has_letters = chrs().any(|c| c.is_alphabetic());
let has_lowercase = chrs().any(|c| c.is_alphabetic() && !c.is_uppercase());
if has_letters && has_text && !has_lowercase { "Whoa, chill out!" }
else if chrs().as_str().ends_with("?") { "Sure." }
else if !has_text { "Fine. Be that way!" }
else { "Whatever." }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment