Splits the given array into an array of chunks of up to the given length.

Type signature

(count: number) => <T>(xs: T[]) => T[] | T[][]

Examples

chunk(2)(["a", "b", "c", "d"]);
// ⇒ [['a', 'b'], ['c', 'd']]
Try in REPL
chunk(3)(["a", "b", "c", "d"]);
// ⇒ [['a', 'b', 'c'], ['d']]
Try in REPL

Questions

  • How to split an array into chunks?
  • How to split an array into chunks of the same size?

TypeScript sourceJavaScript source