@stoking: We independently came to very similar solutions. @Hallicon, I just 
did this last week; so this solution passes the unit tests. I like naming the 
variables in a way that explains their logic; this eliminates the need for 
comments. The if-expression is the procedure's final expression, which means 
this procedure will return the string from the if-expression.
    
    
    import strutils
    
    proc hey*(s: string): string =
      let strippedS = s.strip
      let isQuestion = strippedS.endsWith("?")
      let isYell = (strippedS == strippedS.toUpperAscii) and 
(strippedS.find(UppercaseLetters) >= 0)
      let isSilence = (len(strippedS) == 0)
      if isYell and isQuestion:
        "Calm down, I know what I'm doing!"
      elif isYell:
        "Whoa, chill out!"
      elif isQuestion:
        "Sure."
      elif isSilence:
        "Fine. Be that way!"
      else:
        "Whatever."
    
    
    Run

Reply via email to