-
Notifications
You must be signed in to change notification settings - Fork 1
chunk
Subhajit Sahu edited this page May 19, 2020
·
24 revisions
Breaks iterable into chunks of given size. 🏃 📼 📦 🌔 📒
iterable.chunk(x, [n], [s]);
// x: an iterable
// n: chunk size (1)
// s: chunk step (n)
const iterable = require('extra-iterable');
var x = [1, 2, 3, 4, 5, 6, 7, 8];
[...iterable.chunk(x, 3)];
// [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]
[...iterable.chunk(x, 2, 3)];
// [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ]
[...iterable.chunk(x, 4, 3)];
// [ [ 1, 2, 3, 4 ], [ 4, 5, 6, 7 ], [ 7, 8 ] ]