Skip to content

Instantly share code, notes, and snippets.

@zigen
Created September 16, 2015 09:26
Show Gist options
  • Save zigen/c419e4ea635be63e33e4 to your computer and use it in GitHub Desktop.
Save zigen/c419e4ea635be63e33e4 to your computer and use it in GitHub Desktop.
class Array
def group p
arr = self
res = []
start = 0
last = 0
while start + p <= arr.length
last = start + p -1
res.push(arr[start..last])
start = last + 1
end
res
end
end
print [1,2,3,4,5,6].group(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment