chunk(size: Int = 0) -> [[Element]]

Create an array of elements split in to groups by the length of size. If array can't be split evenly, the final chunk contains all the remain elements.

Parameters

  • size: The length of each chunk. 0 by default.

Returns

The new array contains chunks

[1,2,3,4,5].chunk(size: 2)
// -> [[1,2],[3,4],[5]]