| [a762898] | 1 | /**
|
|---|
| 2 | * Returns the last element of an array.
|
|---|
| 3 | *
|
|---|
| 4 | * This function takes an array and returns the last element of the array.
|
|---|
| 5 | * If the array is empty, the function returns `undefined`.
|
|---|
| 6 | *
|
|---|
| 7 | * Unlike some implementations, this function is optimized for performance
|
|---|
| 8 | * by directly accessing the last index of the array.
|
|---|
| 9 | *
|
|---|
| 10 | * @template T - The type of elements in the array.
|
|---|
| 11 | * @param {[...T[], T]} arr - The array from which to get the last element.
|
|---|
| 12 | * @returns {T} The last element of the array, or `undefined` if the array is empty.
|
|---|
| 13 | *
|
|---|
| 14 | * @example
|
|---|
| 15 | * const arr = [1, 2, 3];
|
|---|
| 16 | * const lastElement = last(arr);
|
|---|
| 17 | * // lastElement will be 3
|
|---|
| 18 | *
|
|---|
| 19 | * const emptyArr: number[] = [];
|
|---|
| 20 | * const noElement = last(emptyArr);
|
|---|
| 21 | * // noElement will be undefined
|
|---|
| 22 | */
|
|---|
| 23 | declare function last<T>(arr: readonly [...T[], T]): T;
|
|---|
| 24 | /**
|
|---|
| 25 | * Returns the last element of an array.
|
|---|
| 26 | *
|
|---|
| 27 | * This function takes an array and returns the last element of the array.
|
|---|
| 28 | * If the array is empty, the function returns `undefined`.
|
|---|
| 29 | *
|
|---|
| 30 | * Unlike some implementations, this function is optimized for performance
|
|---|
| 31 | * by directly accessing the last index of the array.
|
|---|
| 32 | *
|
|---|
| 33 | * @template T - The type of elements in the array.
|
|---|
| 34 | * @param {T[]} arr - The array from which to get the last element.
|
|---|
| 35 | * @returns {T | undefined} The last element of the array, or `undefined` if the array is empty.
|
|---|
| 36 | *
|
|---|
| 37 | * @example
|
|---|
| 38 | * const arr = [1, 2, 3];
|
|---|
| 39 | * const lastElement = last(arr);
|
|---|
| 40 | * // lastElement will be 3
|
|---|
| 41 | *
|
|---|
| 42 | * const emptyArr: number[] = [];
|
|---|
| 43 | * const noElement = last(emptyArr);
|
|---|
| 44 | * // noElement will be undefined
|
|---|
| 45 | */
|
|---|
| 46 | declare function last<T>(arr: readonly T[]): T | undefined;
|
|---|
| 47 |
|
|---|
| 48 | export { last };
|
|---|