Created
August 8, 2015 22:48
-
-
Save kangkyu/07317a40b090e33aa14e to your computer and use it in GitHub Desktop.
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
# Take this array: | |
a = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] | |
# and transform it into this array | |
# [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 0, 0]] | |
flat = a.flatten | |
b = [] | |
while flat.length > 0 | |
temp = flat.shift(3) | |
while temp.length < 3 | |
temp << 0 | |
end | |
b << temp | |
end | |
b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment