Commits

tednaleid committed b919524

answer to 39

Comments (0)

Files changed (1)

src/four_clojure/answered.clj

 (= (my-replicate [[1 2] [3 4]] 2) '([1 2] [1 2] [3 4] [3 4]))
 (= (my-replicate [44 33] 2) [44 44 33 33])
 
-; http://www.4clojure.com/problem/
-;
-;
+; http://www.4clojure.com/problem/39
+; Interleave Two Seqs
+; Write a function which takes two sequences and returns the first item from each, then the second item from each, then the third, etc.
+; restriction: interleave
 
+(defn my-interleave ([x y]
+        (and (seq x) (seq y) (cons (first x) (cons (first y) 
+                                 (my-interleave (rest x) (rest y)))))))
+; or
+; mapcat list
+  
+
+(= (my-interleave [1 2 3] [:a :b :c]) '(1 :a 2 :b 3 :c))
+(= (my-interleave [1 2] [3 4 5 6]) '(1 3 2 4))
+(= (my-interleave [1 2 3 4] [5]) [1 5])
+(= (my-interleave [30 20] [25 15]) [30 25 20 15])
 
 ; http://www.4clojure.com/problem/
 ;