Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/underglow/extensions/array.rb
Instance Method Summary collapse
Instance Method Details
#bucketize(count) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/underglow/extensions/array.rb', line 2 def bucketize(count) raise ArgumentError unless count.kind_of? Fixnum count = count.to_i return self if count <= 0 j = length / count.to_f result = each_with_index.chunk { |_, i| (i / j).floor }.map { |_, v| v.map(&:first) } result << [] until result.length == count result end |