Last active
August 29, 2015 14:12
-
-
Save vumanhcuongit/321c758b4aeb3488a534 to your computer and use it in GitHub Desktop.
Interleave Array
This file contains hidden or 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
| def interleave(a, b) | |
| return [a, b].transpose.flatten if a.size == b.size | |
| if a.size > b.size | |
| b << nil | |
| else | |
| a << nil | |
| end | |
| [a, b].transpose.flatten.compact | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment