Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 8x 2x | /** * Gets the last element of `array`. * @param array the array * @param defaultValue default value * @signature * P.last(array) * P.last(array, default) * @example * P.last([1, 2, 3]) // => 3 * P.last([]) // => undefined * P.last([], 2) // => 2 * P.last([1], 2) // => 1 * @category Array */ export function last<T>(array: readonly T[]): T | undefined; export function last<T>(array: readonly T[], defaultValue: T): T; export function last<T>(array: readonly T[], defaultValue?: T): T | undefined { return array[array.length - 1] || defaultValue; } |