Created
April 27, 2011 12:55
-
-
Save telamon/944202 to your computer and use it in GitHub Desktop.
JS array.inGroupsOf() behaviour for Ruby
This file contains 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
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