Monday, January 27, 2014

99 Clojure Problems – 14: Duplicate the Elements of a List


(deftest p14-duplicate
  (is (= '(a a b b c c c c d d) (duplicate '(a b c c d)))))


A straightforward solution just uses reduce to conjoin the current element twice with an accumulator.

Read more about this series.

No comments: