Skip to content

Instantly share code, notes, and snippets.

@telamon
Created April 27, 2011 12:55
Show Gist options
  • Save telamon/944202 to your computer and use it in GitHub Desktop.
Save telamon/944202 to your computer and use it in GitHub Desktop.
JS array.inGroupsOf() behaviour for Ruby
class Array
def groups_of(s)
resp = []
g=[]
self.each do |i|
g << i
if g.count == s
resp << g
g= []
end
end
resp << g unless g.empty?
resp
end
alias / groups_of
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment