Created
June 7, 2012 18:43
-
-
Save theirix/2890701 to your computer and use it in GitHub Desktop.
buckets
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
# breaks array to buckets delimited by a specified item | |
def buckets array, &block | |
buckets = [] | |
while true | |
cur = array.find_index &block | |
buckets << array unless cur | |
break unless cur | |
buckets << array[0...cur] if cur > 0 | |
array = array.drop(cur+1) | |
end | |
buckets | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment