bob.clj

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(ns bob
  (:require [clojure.string :refer [upper-case lower-case blank? ends-with?]]))

(defn is-upper? [text]
  "Determines whether text is upper case"
  (and (= (upper-case text) text)
       (not= (lower-case text) text)))

(defn is-question? [text]
  "Determines whether text is a question"
  (ends-with? text "?"))

(defn response-for [text]
  (condp apply [text]
    blank? "Fine. Be that way!"
    is-upper? "Whoa, chill out!"
    is-question? "Sure."
    "Whatever."))

Comments

It's a bit longer, but only because it's forced me to abstract out another method - and the core logic itself is a little cleaner now. And it's good to know different ways to do this.

Also added a question mark to is-upper

helenst commented 21 March 2016 at 15:01 UTC

You're not logged in right now. Please login via GitHub to comment