Thanks Tamreen. Your solution will have to be wrapped in another vec call. I will use Miekel's:
(reduce into [] (repeat n xs)). ________________________________ From: [email protected] [mailto:[email protected]] On Behalf Of Tamreen Khan Sent: Wednesday, July 13, 2011 11:02 AM To: [email protected] Subject: Re: Repeating a vector n times 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 <[email protected]> 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 [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] <mailto:clojure%[email protected]> 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 [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
