Skip to content

Commit

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

(ns ex.q041)

(defn ans
"Problem 41, Drop Every Nth Item"
[coll n]
(mapcat #(if (= n (count %)) (butlast %) %) (partition-all n coll)))
11 changes: 11 additions & 0 deletions test/ex/q041_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;; https://4clojure.oxal.org/#/problem/041

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

(t/deftest test-q41
(t/testing "Problem 41, Drop Every Nth Item"
(t/is (= [1 2 4 5 7 8] (sut/ans [1 2 3 4 5 6 7 8] 3)))
(t/is (= [:a :c :e] (sut/ans [:a :b :c :d :e :f] 2)))
(t/is (= [1 2 3 5 6] (sut/ans [1 2 3 4 5 6] 4)))))

0 comments on commit 6e07a91

Please sign in to comment.