Skip to content

Instantly share code, notes, and snippets.

@CasonBarnhill
Created November 2, 2015 22:55
Show Gist options
  • Save CasonBarnhill/9bd4250ebacbf7315516 to your computer and use it in GitHub Desktop.
Save CasonBarnhill/9bd4250ebacbf7315516 to your computer and use it in GitHub Desktop.
{
public class Bob
{
internal string hey(string remark)
{
if (NotSayingAnything(remark))
{
return "Fine. Be that way!";
}
if (IsShouting(remark))
{
return "Whoa, chill out!";
}
if (IsQuestion(remark))
{
return "Sure.";
}
return "Whatever.";
}
private bool NotSayingAnything(string remark)
{
if (string.IsNullOrWhiteSpace(remark))
return true;
return false;
}
private bool IsQuestion(string remark)
{
if (remark.EndsWith("?"))
return true;
return false;
}
private bool IsShouting(string remark)
{
if (!remark.ToCharArray().Any(c => char.IsUpper(c)))
return false;
bool allUpperCase = remark.ToCharArray().All(c => char.IsUpper(c)|| char.IsPunctuation(c)|| char.IsSeparator(c)||char.IsSymbol(c)||char.IsNumber(c));
return allUpperCase;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment