Created
March 30, 2013 19:38
-
-
Save maliqq/5278058 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
a = [1,2,3,5,6,7,10,11,12,14,15] | |
def split_gaps(a) | |
gaps = [] | |
buffer = a.inject([]) { |buffer, item| | |
prev = buffer[buffer.size - 1] | |
if prev && item - prev > 1 | |
gaps << buffer | |
[] | |
else | |
buffer << item | |
buffer | |
end | |
} | |
gaps << buffer | |
end | |
puts split_gaps(a).inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment