Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maximusfox/2fe154e4e0d59cce3982406046651a35 to your computer and use it in GitHub Desktop.
Save maximusfox/2fe154e4e0d59cce3982406046651a35 to your computer and use it in GitHub Desktop.
a = [1,2,3,4,5]
# 2 new arrays
left,right = a.each_slice( (a.size/2.0).round ).to_a
# left == [1, 2, 3]
# right == [4, 5]
# make array 2-dimensional
a.each_slice( (a.size/2.0).round ).to_a
# a == [[1, 2, 3], [4, 5]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment