chunk - nodef/extra-set GitHub Wiki

Break set into chunks of given size.

function chunk(x, n, s)
// x: a set
// n: chunk size [1]
// s: chunk step [n]
const set = require('extra-set');

var x = new Set([1, 2, 3, 4, 5, 6, 7, 8]);
set.chunk(x, 3);
// → [ Set(3) { 1, 2, 3 }, Set(3) { 4, 5, 6 }, Set(2) { 7, 8 } ]

set.chunk(x, 2, 3);
// → [ Set(2) { 1, 2 }, Set(2) { 4, 5 }, Set(2) { 7, 8 } ]

set.chunk(x, 4, 3);
// → [ Set(4) { 1, 2, 3, 4 }, Set(4) { 4, 5, 6, 7 }, Set(2) { 7, 8 } ]

References