Skip to content

Commit

Permalink
Add q40
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkun committed Aug 7, 2024
1 parent 2326df1 commit e6b3861
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ex/q040.clj
Original file line number Diff line number Diff line change
@@ -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)))
11 changes: 11 additions & 0 deletions test/ex/q040_test.clj
Original file line number Diff line number Diff line change
@@ -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])))))

0 comments on commit e6b3861

Please sign in to comment.