Skip to content
Subhajit Sahu edited this page May 17, 2020 · 24 revisions

Breaks iterable into chunks of given size. 🏃 📼 📦 🌔 📒

iterable.chunk(x, [s], [n]);
// x: an iterable
// s: chunk step (1)
// n: chunk size (s)
const iterable = require('extra-iterable');

var x = [1, 2, 3, 4, 5];
[...iterable.chunk(x, 2)];
// [ [ 1, 2 ], [ 3, 4 ], [ 5 ] ]

[...iterable.chunk(x, 3)];
// [ [ 1, 2, 3 ], [ 4, 5 ] ]

references

Clone this wiki locally