September 17, 2018

Exercism - Challenge

I found this great website called Exercism where you can solve challenges and wait for mentors to comment your solution.

   

   

The platform was created by Katrina Owen which is a Ruby veteran developer. The main idea about the exercises is to provide not only solutions that solve the problem, but to explore the simple problem ahead of you and learn with it.

   

Watch her presentation about the Bob problem: Overkill

This is my solution to the same problem in Clojure:

   

(ns bob)

(defn uppercase? [s]
  (every? #(Character/isUpperCase %)
          (clojure.string/replace s #"\?|\!" "")))

(def lowercase? (complement uppercase?))

(defn regular-question? [s]
  (and (lowercase? s) (re-find #"\?$" s)))

(defn yell-question? [s]
  (and (uppercase? s) (re-find #"\?$" s)))

(defn said-something? [s]
  (empty? (clojure.string/replace s #"\s" "")))

(def yell? uppercase?)


(defn response-for [s]
  (cond
    (regular-question? s)
    "Sure."
    (yell-question? s)
    "Calm down, I know what I'm doing!"
    (yell? s)
    "Whoa, chill out!"
    (said-something? s)
    "Fine. Be that way!"
    :else
    "Whatever.")
  )

   

It did passed all tests. I will post my solutions for each of the problems in the platform. The idea is to come back to some problem and refactor it, so I can improve or explore some new functionality of the Clojure language or even solve it in a different language that I might be learning at a time.

Find all the solutions with the tag #exercism! Let's go!

Tags: clojure exercism