Created
April 11, 2016 18:46
-
-
Save anonymous/6bf24fd0e8536dc0935c8feba8c4461c to your computer and use it in GitHub Desktop.
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 chunk | |
ret = [] | |
current = nil | |
current_a = [] | |
self.each do |x| | |
if x != current | |
ret.push current_a | |
current = x | |
current_a = [] | |
end | |
current_a.push x | |
end | |
ret.slice! 0 #A little bug in the logic makes this necessary | |
ret | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment