1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00

problems(js): add “2619. Array Prototype Last”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-06-03 20:30:42 +02:00
parent 86599c22a7
commit de8ef50ac8
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,13 @@
Array.prototype.last = function() {
if (!this.length) {
// empty array, ideally should throw an exception
return -1;
}
return this[this.length - 1];
};
/**
* const arr = [1, 2, 3];
* arr.last(); // 3
*/