Skip to main content
edited for readability/grammar
Source Link
the Tin Man
  • 160.9k
  • 44
  • 222
  • 308

Let's say I have the following code:

a = ["Cat", "Dog", "Mouse"]
s = ["and", "&"]

I want to merge the array s into array a which would give me:

["Cat", "and", "Dog", "&", "Mouse"]

Looking through the Ruby arrayArray and enumerableEnumerable docs, I don't see such a method that will accomplish this. Any

Is there a way I can do this without iterating through each array?

Let's say I have the following code:

a = ["Cat", "Dog", "Mouse"]
s = ["and", "&"]

I want to merge the array s into array a which would give me:

["Cat", "and", "Dog", "&", "Mouse"]

Looking through the Ruby array and enumerable docs, I don't see such a method that will accomplish this. Any way I can do this without iterating through each array?

I have the following code:

a = ["Cat", "Dog", "Mouse"]
s = ["and", "&"]

I want to merge the array s into array a which would give me:

["Cat", "and", "Dog", "&", "Mouse"]

Looking through the Ruby Array and Enumerable docs, I don't see such a method that will accomplish this.

Is there a way I can do this without iterating through each array?

deleted 11 characters in body
Source Link
Chris Ledet
  • 11.6k
  • 7
  • 42
  • 47

Let's say I have the following code:

a = ["Cat", "Dog", "Mouse"]
s = ["and", "&"]

I want to merge the array s into array a which would give me:

["Cat", "and", "Dog", "&", "Mouse"]

Looking through the Ruby array and enumerable docs, I don't see such a method that will accomplish this. Any way I can do this without writing a loop foriterating through each of these arraysarray?

Let's say I have the following code:

a = ["Cat", "Dog", "Mouse"]
s = ["and", "&"]

I want to merge the array s into array a which would give me:

["Cat", "and", "Dog", "&", "Mouse"]

Looking through the Ruby array and enumerable docs, I don't see such a method that will accomplish this. Any way I can do this without writing a loop for each of these arrays?

Let's say I have the following code:

a = ["Cat", "Dog", "Mouse"]
s = ["and", "&"]

I want to merge the array s into array a which would give me:

["Cat", "and", "Dog", "&", "Mouse"]

Looking through the Ruby array and enumerable docs, I don't see such a method that will accomplish this. Any way I can do this without iterating through each array?

I changed the title so it matches the example a bit better.
Link
DigitalRoss
  • 146.7k
  • 25
  • 254
  • 336

Merge and interleave two arrays in Ruby

edited tags
Link
Andrew Grimm
  • 82.2k
  • 58
  • 209
  • 355
Loading
Source Link
Chris Ledet
  • 11.6k
  • 7
  • 42
  • 47
Loading