Created
January 15, 2011 22:10
-
-
Save eltiare/781316 to your computer and use it in GitHub Desktop.
Interleaves another array into the current one, returns a new array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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