Search⌘ K

Exercise 2: Interleaving

Explore how to interleave two strings into an array using Ruby's array class. This exercise helps you understand array manipulation by alternating elements, improving your practical skills with built-in Ruby arrays.

We'll cover the following...

Given two strings of length 5, create an array of length 10 such that these two input strings appear as array elements in alternating positions.

Example

input_string_1 = "ha"
input_String_2 = "he"

result = ["ha", "he", "ha", "he", "ha", "he", "ha", "he", "ha", "he"]

Try it yourself

Ruby
def interleaving(input_string_1, input_string_2)
result = ""
#Start your code here
return result
end