Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/itertools/mod.ts>chunked

🦕 A TypeScript port of Python's itertools and more-itertools for Deno
Latest
function chunked
import { chunked } from "https://deno.land/x/itertools@v1.1.2/mod.ts";

Break iterable into lists of length size:

[...chunked([1, 2, 3, 4, 5, 6], 3)]
// [[1, 2, 3], [4, 5, 6]]

If the length of iterable is not evenly divisible by size, the last returned list will be shorter:

[...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]
// [[1, 2, 3], [4, 5, 6], [7, 8]]

Parameters

iterable: Iterable<T>
size: number

Returns

Iterable<Array<T>>