Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/rbbt/util/misc.rb
Instance Method Summary collapse
-
#chunk(num) ⇒ Object
Divides the array into
numchunks of the same size by placing one element in each chunk iteratively.
Instance Method Details
#chunk(num) ⇒ Object
Divides the array into num chunks of the same size by placing one element in each chunk iteratively.
97 98 99 100 101 102 103 104 105 |
# File 'lib/rbbt/util/misc.rb', line 97 def chunk(num) chunks = [] each_with_index{|e, i| c = i % num chunks[c] ||=[] chunks[c] << e } chunks end |