Skip to content

Instantly share code, notes, and snippets.

@eltiare
Created January 15, 2011 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eltiare/781316 to your computer and use it in GitHub Desktop.
Save eltiare/781316 to your computer and use it in GitHub Desktop.
Interleaves another array into the current one, returns a new array
class Array
def interleave(other)
arr = []
size.times { |i| arr << self[i]; arr << other[i] unless i + 1 > other.size }
left = other[size - 1 .. -1]
arr += left if left
arr
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment