chunk
优质
小牛编辑
141浏览
2023-12-01
Breaks this sequence into chunks (arrays) of a specified length.
Signature
Sequence.chunk = function(size) { /*...*/ }
Sequence.chunk = function chunk(size) { if (size < 1) { throw new Error("You must specify a positive chunk size."); } return new ChunkedSequence(this, size); }
Name | Type(s) | Description |
---|---|---|
size | number | The size of each chunk. |
returns | Sequence | The resulting sequence of chunks. |
Examples
Lazy([]).chunk(2) // sequence: [] Lazy([1, 2, 3]).chunk(2) // sequence: [[1, 2], [3]] Lazy([1, 2, 3]).chunk(1) // sequence: [[1], [2], [3]] Lazy([1, 2, 3]).chunk(4) // sequence: [[1, 2, 3]] Lazy([1, 2, 3]).chunk(0) // throws