Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def in_groups(number, fill_with = nil)
- if number == 0
- raise IndexOutOfBounds.new
- end
- division = size.fdiv number
- modulo = size % number
- groups = [] of (Int32 | String | Char)
- start = 0
- number.times do |index|
- length = division + (modulo > 0 && modulo > index ? 1 : 0)
- last_group = self[start, length]
- groups << last_group
- last_group << fill_with if fill_with != false &&
- modulo > 0 && length == division
- start += length
- end
- groups
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement