diff --git a/src/ex/q040.clj b/src/ex/q040.clj new file mode 100644 index 0000000..871bad5 --- /dev/null +++ b/src/ex/q040.clj @@ -0,0 +1,8 @@ +;; https://4clojure.oxal.org/#/problem/040 + +(ns ex.q040) + +(defn ans + "Problem 40, Interpose a Seq. restriction: interpose" + [val coll] + (pop (reduce #(conj %1 %2 val) [] coll))) \ No newline at end of file diff --git a/test/ex/q040_test.clj b/test/ex/q040_test.clj new file mode 100644 index 0000000..4b51805 --- /dev/null +++ b/test/ex/q040_test.clj @@ -0,0 +1,11 @@ +;; https://4clojure.oxal.org/#/problem/040 + +(ns ex.q040-test + (:require [clojure.test :as t] + [ex.q040 :as sut])) + +(t/deftest test-q40 + (t/testing "Problem 40, Interpose a Seq" + (t/is (= [1 0 2 0 3] (sut/ans 0 [1 2 3]))) + (t/is (= "one, two, three" (apply str (sut/ans ", " ["one" "two" "three"])))) + (t/is (= [:a :z :b :z :c :z :d] (sut/ans :z [:a :b :c :d]))))) \ No newline at end of file