Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Renamed the Array
.split
method to .segment
, which better refle…
…cts its functionality. Example: func consecutive_partitions(array, callback) { for k in (0..array.len) { combinations(array.len, k, {|*indices| var t = segment(array, indices...) if (t.sum_by{.len} == array.len) { callback(t) } }) } } var arr = [1,2,3,4,5] consecutive_partitions(arr, { .say }) Output: [[1, 2, 3, 4, 5]] [[1], [2, 3, 4, 5]] [[1, 2], [3, 4, 5]] [[1, 2, 3], [4, 5]] [[1, 2, 3, 4], [5]] [[1], [2], [3, 4, 5]] [[1], [2, 3], [4, 5]] [[1], [2, 3, 4], [5]] [[1, 2], [3], [4, 5]] [[1, 2], [3, 4], [5]] [[1, 2, 3], [4], [5]] [[1], [2], [3], [4, 5]] [[1], [2], [3, 4], [5]] [[1], [2, 3], [4], [5]] [[1, 2], [3], [4], [5]] [[1], [2], [3], [4], [5]] - Added the new Array `.split(obj)` method, which splits a given array by the given object. Example: say [1,2,0,3,0,4].split(0) #=> [[1, 2], [3], [4]] When a block is given for the object, the `.split_by{...}` method is called. say [1,2,0,3,0,4].split { _ == 0 } #=> [[1, 2], [3], [4]]
- Loading branch information