Skip to content

Instantly share code, notes, and snippets.

@PEZ
Last active April 25, 2024 18:28
Show Gist options
  • Save PEZ/03788b118a3d7923f7aae143e8ef1aee to your computer and use it in GitHub Desktop.
Save PEZ/03788b118a3d7923f7aae143e8ef1aee to your computer and use it in GitHub Desktop.
Drop Every Nth Item – Rich 4Clojure Problem 41 – See: https://github.com/PEZ/rich4clojure
(ns rich4clojure.easy.problem-041
(:require [hyperfiddle.rcf :refer [tests]]))
;; = Drop Every Nth Item =
;; By 4Clojure user: dbyrne
;; Difficulty: Easy
;; Tags: [seqs]
;;
;; Write a function which drops every Nth item from a
;; sequence.
(def __ :tests-will-fail)
(comment
)
(tests
(__ [1 2 3 4 5 6 7 8] 3) := [1 2 4 5 7 8]
(__ [:a :b :c :d :e :f] 2) := [:a :c :e]
(__ [1 2 3 4 5 6] 4) := [1 2 3 5 6])
;; To participate, fork:
;; https://github.com/PEZ/rich4clojure
;; Post your solution below, please!
@natef-GuruTech
Copy link

(defn drop-at [coll idcs]
  (->> coll
       (map-indexed (fn [i n] [i n]))
       (remove (fn [[i x]] (some #{i} idcs)))
       (map second)))

(def __ (fn [xs n]
          (let [idcs (map dec (range 0 (inc (count xs)) n))]
            (drop-at xs (rest idcs)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment