Skip to content

Commit

Permalink
Add q30
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkun committed Jul 31, 2024
1 parent 80fa577 commit a6379bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ex/q030.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
;; https://4clojure.oxal.org/#/problem/030

(ns ex.q030)

(defn ans
"Problem 30, Compress a Sequence. (remove consecutive duplicates from a sequence)"
[coll]
(reduce #(if (= (last %1) %2) %1 (conj %1 %2)) [] coll))
11 changes: 11 additions & 0 deletions test/ex/q030_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;; https://4clojure.oxal.org/#/problem/030

(ns ex.q030-test
(:require [clojure.test :as t]
[ex.q030 :as sut]))

(t/deftest test-q30
(t/testing "Problem 30, Compress a Sequence"
(t/is (= "Leroy" (apply str (sut/ans "Leeeeeerrroyyy"))))
(t/is (= '(1 2 3 2 3) (sut/ans [1 1 2 3 3 2 2 3])))
(t/is (= '([1 2] [3 4] [1 2]) (sut/ans [[1 2] [1 2] [3 4] [1 2]])))))

0 comments on commit a6379bb

Please sign in to comment.