Mwnci batch() Function

Syntax

batch(array,size)

Description

The batch() function splits an array into smaller batch (chunk) sizes.
It is possible that the last chunk is shorter than its predecessors unless the array’s length is divisible by the desired batch size. To ensure that all the chunks have an equal length at all times, you can pad the last chunk with default values.

Example

a=1..10
println(a)
println(batch(a,4))
println(batch(a,5))
println(batch(a,6))


[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]
[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
[[1, 2, 3, 4, 5, 6], [7, 8, 9, 10]]