Skip to main content

2619. Array Prototype Last

https://leetcode.com/problems/array-prototype-last/

Javascript

Array.prototype.last = function() {
if (this.length <= 0) {
return -1
}
return this[this.length - 1]
};

Typescript

declare global {
interface Array<T> {
last(): T | -1;
}
}

Array.prototype.last = function() {
if (this.length <= 0) {
return -1
}
return this[this.length - 1]
};