ts-data-forge
    Preparing search index...
    • Returns a new array with a value inserted at the specified index.

      Type Parameters

      • const Ar extends readonly unknown[]
      • const V = Ar[number]

      Parameters

      Returns IsFixedLengthList<Ar> extends true
          ? ArrayOfLength<CastToNumber<Increment<Ar["length"]>>, Ar[number] | V>
          : readonly [Ar[number] | V, Ar[number] | V]

      const numbers = [1, 2, 4] as const;

      const withThree = Arr.toInserted(numbers, 2, 3);

      const appendFive = Arr.toInserted(3, 5)(numbers);

      assert.deepStrictEqual(withThree, [1, 2, 3, 4]);

      assert.deepStrictEqual(appendFive, [1, 2, 4, 5]);
    • Returns a new array with a value inserted at the specified index.

      Type Parameters

      • const V

      Parameters

      Returns <const Ar extends readonly unknown[]>(
          array: Ar,
      ) => IsFixedLengthList<Ar> extends true
          ? ArrayOfLength<CastToNumber<Increment<Ar["length"]>>, V | Ar[number]>
          : readonly [V | Ar[number], V | Ar[number]]

      const numbers = [1, 2, 4] as const;

      const withThree = Arr.toInserted(numbers, 2, 3);

      const appendFive = Arr.toInserted(3, 5)(numbers);

      assert.deepStrictEqual(withThree, [1, 2, 3, 4]);

      assert.deepStrictEqual(appendFive, [1, 2, 4, 5]);