PokéRogue
    Preparing search index...

    Function subArray

    • Get a subarray view of the first n elements of an array-like object, to use with constructing a new one, with minimal allocaitons.

      Type Parameters

      Parameters

      • arr: A

        The array-like object to take elements from

      • n: number

        The maximum number of elements to take. If

      Returns A

      An array-like object whose length property is guaranteed to be <= n

      This is primarily useful for setting elements of a TypedArray using its set method.

      const arr = new Uint8Array(3);
      const other = [1, 2, 3, 4, 5];
      // Using arr.set(other) would throw, as other.length > arr.length
      arr.set(subArray(other, arr.length));

      @throws {TypeError}
      If `arr` is not an array or typed array (though typescript should prevent this