summary refs log tree commit diff stats
path: root/clojure
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-06 18:33:47 +0530
committerAndinus <andinus@nand.sh>2021-09-06 18:33:47 +0530
commit2c3463a677d01dfc027bc518de91eeeaebc14a5b (patch)
treed998be4ad77637e75274282eb590c533cda9b00a /clojure
parent708ed21ef98343bf39c2426c762f6ce930955460 (diff)
downloadexercism-2c3463a677d01dfc027bc518de91eeeaebc14a5b.tar.gz
Clojure: Raindrops: Improve solution
Avoids logic repetition.
Diffstat (limited to 'clojure')
-rw-r--r--clojure/raindrops/src/raindrops.clj20
1 files changed, 8 insertions, 12 deletions
diff --git a/clojure/raindrops/src/raindrops.clj b/clojure/raindrops/src/raindrops.clj
index 8815f2d..fda3fef 100644
--- a/clojure/raindrops/src/raindrops.clj
+++ b/clojure/raindrops/src/raindrops.clj
@@ -1,15 +1,11 @@
 (ns raindrops)
 
 (defn convert [number]
-  (def drops "")
-
-  (if (== (mod number 3) 0)
-    (def drops (str drops "Pling")))
-  (if (== (mod number 5) 0)
-    (def drops (str drops "Plang")))
-  (if (== (mod number 7) 0)
-    (def drops (str drops "Plong")))
-
-  (if (= drops "")
-    (def drops (str number)))
-  drops)
+  (let [drops (apply str
+                     (map (fn [factor string]
+                            (if (== (mod number factor) 0)
+                              string nil))
+                          [3 5 7]
+                          ["Pling" "Plang" "Plong"]))]
+    (if (= drops "")
+      (str number) drops)))