ts-data-forge
    Preparing search index...
    • Partitions an array into sub-arrays of a specified size.

      Type Parameters

      • N extends WithSmallInt<
            number & {
                "!=0": true;
                "> -2^16": true;
                "> -2^32": true;
                ">= -2^15": true;
                ">= -2^31": true;
                ">=0": true;
                Finite: true;
                Int: true;
                NaNValue: false;
            } & Readonly<
                {
                    "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
                },
            > & {
                "< 2^32": true;
                "> -2^16": true;
                "> -2^32": true;
                ">= -2^15": true;
                ">= -2^31": true;
                ">=0": true;
                Finite: true;
                Int: true;
                NaNValue: false;
                SafeInt: true;
            },
            40,
        >
      • E

      Parameters

      • array: readonly E[]
      • chunkSize: N

      Returns readonly (readonly E[])[]

      const values = [1, 2, 3, 4, 5] as const;

      const pairs = Arr.partition(values, 2);
      const triples = Arr.partition(3)(values);

      const expectedPairs = [[1, 2], [3, 4], [5]] as const;

      assert.deepStrictEqual(pairs, expectedPairs);
      assert.deepStrictEqual(triples, [
      [1, 2, 3],
      [4, 5],
      ]);

      const pairs2 = Arr.chunk([1, 2, 3, 4, 5, 6], 2);

      assert.deepStrictEqual(pairs2, [
      [1, 2],
      [3, 4],
      [5, 6],
      ]);
    • Partitions an array into sub-arrays of a specified size.

      Type Parameters

      • N extends WithSmallInt<
            number & {
                "!=0": true;
                "> -2^16": true;
                "> -2^32": true;
                ">= -2^15": true;
                ">= -2^31": true;
                ">=0": true;
                Finite: true;
                Int: true;
                NaNValue: false;
            } & Readonly<
                {
                    "TSTypeForgeInternals--edd2f9ce-7ca5-45b0-9d1a-bd61b9b5d9c3": unknown;
                },
            > & {
                "< 2^32": true;
                "> -2^16": true;
                "> -2^32": true;
                ">= -2^15": true;
                ">= -2^31": true;
                ">=0": true;
                Finite: true;
                Int: true;
                NaNValue: false;
                SafeInt: true;
            },
            40,
        >

      Parameters

      • chunkSize: N

      Returns <E>(array: readonly E[]) => readonly (readonly E[])[]

      const values = [1, 2, 3, 4, 5] as const;

      const pairs = Arr.partition(values, 2);
      const triples = Arr.partition(3)(values);

      const expectedPairs = [[1, 2], [3, 4], [5]] as const;

      assert.deepStrictEqual(pairs, expectedPairs);
      assert.deepStrictEqual(triples, [
      [1, 2, 3],
      [4, 5],
      ]);

      const pairs2 = Arr.chunk([1, 2, 3, 4, 5, 6], 2);

      assert.deepStrictEqual(pairs2, [
      [1, 2],
      [3, 4],
      [5, 6],
      ]);