Sha256: 772d4c2b23f85a898605dfe21f659b385f47dce3045b6e00612518d1c2266397
Contents?: true
Size: 1.14 KB
Versions: 17
Compression:
Stored size: 1.14 KB
Contents
from strutils import endsWith, strip from unicode import isLower, isUpper, isWhiteSpace, runes proc isSilence(s: string): bool = for r in runes(s): if not isWhiteSpace(r): return false return true proc isYelling(s: string): bool = var nUpperRunes = 0 for r in runes(s): if isLower(r): return false elif isUpper(r): inc(nUpperRunes) return nUpperRunes > 0 proc isQuestion(s: string): bool = return s.strip().endsWith("?") proc hey*(msg: string): string {.noSideEffect.} = ## Returns the response of a lackadaisical teenager to a futile attempt to ## communicate with him. ## ## .. code-block:: nimrod ## let greeting = "Hi, Bob!" ## assert hey(greeting) == "Whatever." ## ## let question == "What's up, Bob?" ## assert hey(question) == "Sure." ## ## let rage = "TALK TO ME!!!" ## assert hey(rage) == "Whoa, chill out!" ## ## let resignation = "" ## assert hey(resignation) == "Fine. Be that way!" if isSilence(msg): return "Fine. Be that way!" elif isYelling(msg): return "Whoa, chill out!" elif isQuestion(msg): return "Sure." else: return "Whatever."
Version data entries
17 entries across 17 versions & 1 rubygems