Skip to content
Subhajit Sahu edited this page Jun 17, 2020 · 11 revisions

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

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

var x = new Map([
  ['a', 1], ['b', 2], ['c', 3], ['d', 4],
  ['e', 5], ['f', 6], ['g', 7], ['h', 8]
]);
map.chunk(x, 3);
// [
//   Map(3) { 'a' => 1, 'b' => 2, 'c' => 3 },
//   Map(3) { 'd' => 4, 'e' => 5, 'f' => 6 },
//   Map(2) { 'g' => 7, 'h' => 8 }
// ]

map.chunk(x, 2, 3);
// [
//   Map(2) { 'a' => 1, 'b' => 2 },
//   Map(2) { 'd' => 4, 'e' => 5 },
//   Map(2) { 'g' => 7, 'h' => 8 }
// ]

map.chunk(x, 4, 3);
// [
//   Map(4) { 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 },
//   Map(4) { 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7 },
//   Map(2) { 'g' => 7, 'h' => 8 }
// ]

references

Clone this wiki locally