@@ -424,11 +424,12 @@ export const max = (data: MIR): number | undefined => {
424
424
} ;
425
425
426
426
/**
427
- * Returns the N-th integer of the given MultiIntegerRange .
427
+ * Returns the integer at the specified 0-based index .
428
428
* If a negative index is given, the index is counted from the end.
429
429
* @param data - The value.
430
430
* @param index - The 0-based index of the integer to return. Can be negative.
431
- * @returns The N-th integer. Returns `undefined` if the index is out of bounds.
431
+ * @returns The integer at the specified index.
432
+ * Returns `undefined` if the index is out of bounds.
432
433
* @example
433
434
* at([[2, 4], [8, 10]], 4); // 9
434
435
* at([[2, 4], [8, 10]], 6); // undefined
@@ -438,8 +439,9 @@ export const at = (data: MIR, index: number): number | undefined => {
438
439
if ( index === Infinity || index === - Infinity )
439
440
throw new RangeError ( 'at() was invoked with an invalid index' ) ;
440
441
if (
441
- ( index >= 0 && data [ 0 ] ?. [ 0 ] === - Infinity ) ||
442
- ( index < 0 && data [ data . length - 1 ] ?. [ 1 ] === Infinity )
442
+ data . length > 0 &&
443
+ ( ( index >= 0 && data [ 0 ] [ 0 ] === - Infinity ) ||
444
+ ( index < 0 && data [ data . length - 1 ] [ 1 ] === Infinity ) )
443
445
) {
444
446
throw new RangeError ( 'at() was invoked on an unbounded range' ) ;
445
447
}
0 commit comments