Skip to content

Instantly share code, notes, and snippets.

@kangkyu
Created August 8, 2015 22:48
Show Gist options
  • Save kangkyu/07317a40b090e33aa14e to your computer and use it in GitHub Desktop.
Save kangkyu/07317a40b090e33aa14e to your computer and use it in GitHub Desktop.
# 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