yjcyxky
10/18/2019 - 3:21 PM

Interleave Two Seqs

Difficulty: Easy

Topics: seqs core-functions

Write a function which takes two sequences and returns the first item from each, then the second item from each, then the third, etc.

(= (__ [1 2 3] [:a :b :c]) '(1 :a 2 :b 3 :c))

(= (__ [1 2] [3 4 5 6]) '(1 3 2 4))

(= (__ [1 2 3 4] [5]) [1 5])

(= (__ [30 20] [25 15]) [30 25 20 15])
(fn inter-leave [first-seq second-seq]
  (let [item-seq1 (first first-seq)
        item-seq2 (first second-seq)]
    (cond 
      (nil? item-seq1) []
      (nil? item-seq2) []
      :default (concat [item-seq1 item-seq2] (inter-leave (rest first-seq) (rest second-seq))))))