RosettaCodeData/Task/Determine-if-a-string-is-squeezable/Clojure/determine-if-a-string-is-squeezable.clj
2023-07-01 13:44:08 -04:00

12 lines
427 B
Clojure

(defn squeeze [s c]
(let [spans (partition-by #(= c %) s)
span-out (fn [span]
(if (= c (first span))
(str c)
(apply str span)))]
(apply str (map span-out spans))))
(defn test-squeeze [s c]
(let [out (squeeze s c)]
(println (format "Input: <<<%s>>> (len %d)\n" s (count s))
(format "becomes: <<<%s>>> (len %d)" out (count out)))))