@@ -424,11 +424,12 @@ export const max = (data: MIR): number | undefined => {
424424} ;
425425
426426/**
427- * Returns the N-th integer of the given MultiIntegerRange .
427+ * Returns the integer at the specified 0-based index .
428428 * If a negative index is given, the index is counted from the end.
429429 * @param data - The value.
430430 * @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.
432433 * @example
433434 * at([[2, 4], [8, 10]], 4); // 9
434435 * at([[2, 4], [8, 10]], 6); // undefined
@@ -438,8 +439,9 @@ export const at = (data: MIR, index: number): number | undefined => {
438439 if ( index === Infinity || index === - Infinity )
439440 throw new RangeError ( 'at() was invoked with an invalid index' ) ;
440441 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 ) )
443445 ) {
444446 throw new RangeError ( 'at() was invoked on an unbounded range' ) ;
445447 }
0 commit comments