How to interlace two arrays
A more in-depth description is available.
1 2 class Array 3 # interlaces an array with another array. 4 # It dovetails the two arrays together. 5 # 6 # [1,2,3,4,5,6].interlace([7,8,9]) # => [1, 7, 2, 8, 3, 9, 4, 5, 6] 7 # 8 # [1,2,3].interlace([1,2,3,4,5]) # => [1, 1, 2, 2, 3, 3, 4, 5] 9 def interlace(other_array) 10 return other_array if self.empty? 11 return [self[0]] + other_array.interlace(self[1..-1]) 12 end 13 end