From cf846156d00c082353541666b3b5df6a6a71655b Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Tue, 7 Jul 2020 21:45:24 -0300 Subject: [PATCH] Solution --- clojure/bob/src/bob.clj | 43 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/clojure/bob/src/bob.clj b/clojure/bob/src/bob.clj index c209347..1b7d840 100644 --- a/clojure/bob/src/bob.clj +++ b/clojure/bob/src/bob.clj @@ -1,5 +1,42 @@ (ns bob) -(defn response-for [s] ;; <- arglist goes here - ;; your code goes here -) +(defn shout? + [x] + (let [filtered (filter #(Character/isLetter %) x)] + (if (empty? filtered) + false + (every? #(Character/isUpperCase %) filtered) + ) + ) + ) + +(defn trim + [x] + (remove #(Character/isWhitespace %) x) + ) + +(defn question? + [x] + (= (last (trim x)) \?) + ) + +(defn silence? + [x] + (empty? (trim x)) + ) + +(defn forceful-question? + [x] + (and (shout? x) (question? x)) + ) + +(defn response-for + [s] + (cond + (silence? s) "Fine. Be that way!" + (forceful-question? s) "Calm down, I know what I'm doing!" + (shout? s) "Whoa, chill out!" + (question? s) "Sure." + :else "Whatever." + ) + )