Damn, Meikel's solution is better, I was thinking: (apply concat (repeat n xs))
On Wed, Jul 13, 2011 at 10:54 AM, Bhinderwala, Shoeb < sabhinderw...@wellington.com> wrote: > ** > > I have to write a function that will take a vector as input, repeat the > elements multiple times and return back a single vector of the repeated > items. I came up with the following but am wondering if there is a better > or simpler way to write this: > > (def xs ["a" "b" "c"]) > > (defn repeat-vec-n > > [xs n] > > (vec > > (reduce concat [] > > (take n (repeat xs))))) > > OUTPUT: > > user=> xs > > ["a" "b" "c"] > > user=> (repeat-vec-n xs 3) > > ["a" "b" "c" "a" "b" "c" "a" "b" "c"] > > *******-- Shoeb* > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en