-
Notifications
You must be signed in to change notification settings - Fork 3
chunk
Subhajit Sahu edited this page Dec 8, 2022
·
11 revisions
Break object into chunks of given size.
Similar: [partition], [chunk].
function chunk(x, n, s)
// x: an object
// n: chunk size [1]
// s: chunk step [n]
const object = require('extra-object');
var x = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8};
object.chunk(x, 3);
// → [ { a: 1, b: 2, c: 3 }, { d: 4, e: 5, f: 6 }, { g: 7, h: 8 } ]
object.chunk(x, 2, 3);
// → [ { a: 1, b: 2 }, { d: 4, e: 5 }, { g: 7, h: 8 } ]
object.chunk(x, 4, 3);
// → [
// → { a: 1, b: 2, c: 3, d: 4 },
// → { d: 4, e: 5, f: 6, g: 7 },
// → { g: 7, h: 8 }
// → ]
- List-Extra.groupsOf: elm
- iterable_chunk: PHP
- array_chunk: PHP
- str_split: PHP
- numpy.split: Python
- _.chunk: lodash
- Array.inGroupsOf: sugarjs
- Array.inGroups: sugarjs
- even-chunks: @addaleax
- chunk: @ryancole
- iterable.chunk: @zhiyelee
- chunk-iterable: @haio [partition]: https://github.com/nodef/extra-object/wiki/partition [chunk]: https://github.com/nodef/extra-object/wiki/chunk