Skip to content

Instantly share code, notes, and snippets.

@PEZ
Last active April 25, 2024 15:55
Show Gist options
  • Save PEZ/9e936a6097fdb1fd7a8418a22e3e1170 to your computer and use it in GitHub Desktop.
Save PEZ/9e936a6097fdb1fd7a8418a22e3e1170 to your computer and use it in GitHub Desktop.
Duplicate a Sequence – Rich 4Clojure Problem 32 – See: https://github.com/PEZ/rich4clojure
(ns rich4clojure.easy.problem-032
(:require [hyperfiddle.rcf :refer [tests]]))
;; = Duplicate a Sequence =
;; By 4Clojure user: dbyrne
;; Difficulty: Easy
;; Tags: [seqs]
;;
;; Write a function which duplicates each element of a
;; sequence.
(def __ :tests-will-fail)
(comment
)
(tests
(__ [1 2 3]) := '(1 1 2 2 3 3)
(__ [:a :a :b :b]) := '(:a :a :a :a :b :b :b :b)
(__ [[1 2] [3 4]]) := '([1 2] [1 2] [3 4] [3 4])
(__ [[1 2] [3 4]]) := '([1 2] [1 2] [3 4] [3 4]))
;; To participate, fork:
;; https://github.com/PEZ/rich4clojure
;; Post your solution below, please!
@simonl91
Copy link

(def __ (fn [cols] (mapcat #(list % %) cols)))

@natef-GuruTech
Copy link

(def __ (fn [c] (mapcat (fn [a] [a a]) c)))
Really loving mapcat today

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