teeworlds_network/lib/array.rb
2022-11-05 17:48:47 +01:00

21 lines
338 B
Ruby

# frozen_string_literal: true
class Array
def groups_of(max_size)
return [] if max_size < 1
groups = []
group = []
each do |item|
group.push(item)
if group.size >= max_size
groups.push(group)
group = []
end
end
groups.push(group) unless group.size.zero?
groups
end
end