Function chunk

  • Breaks an array into chunks of length size. If useRemaining is set to true (default), then any extra elements at the end not long enough for a complete chunk will be included as a shorter array. If useRemaining is false, the remaining elements that do not comprise a complete chunk will be ignored.

    Remarks

    Returns null if size is not a positive integer.

    Example

    import * as A from "flurp/array";

    const pairsAndExtra = A.chunk(2);
    pairsAndExtra([1, 2, 3, 4, 5, 6, 7]); // [[1, 2], [3, 4], [5, 6], [7]]

    const justPairs = A.chunk(2, false);
    justPairs([1, 2, 3, 4, 5, 6, 7]); // [[1, 2], [3, 4], [5, 6]]

    Type Parameters

    • T

    Parameters

    • size: number
    • useRemaining: boolean = true

    Returns ((arr: T[]) => T[][])

      • (arr: T[]): T[][]
      • Parameters

        • arr: T[]

        Returns T[][]