Skip to content

Instantly share code, notes, and snippets.

@prajwalit
Created September 1, 2011 06:47
Show Gist options
  • Save prajwalit/1185597 to your computer and use it in GitHub Desktop.
Save prajwalit/1185597 to your computer and use it in GitHub Desktop.
[4clojure #41] Write a function which drops every Nth item from a sequence.
(defn drop-items [coll x]
(loop [coll coll
x x
res []
c 1]
(if (empty? coll)
res
(recur (rest coll)
x
(if (= c x)
res
(conj res (first coll)))
(if (= c x)
1
(inc c))))))
(drop-items [1 2 3 4 5 6 7 8] 2)
;; => [1 3 5 7]
(drop-items [1 2 3 4 5 6 7 8] 3)
;; => [1 2 4 5 7 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment