Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 750 Bytes

_2619. Array Prototype Last.md

File metadata and controls

42 lines (31 loc) · 750 Bytes

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 10, 2024

Last updated : July 10, 2024


Related Topics : N/A

Acceptance Rate : 74.08 %


Solutions

JavaScript

/**
 * @return {null|boolean|number|string|Array|Object}
 */
Array.prototype.last = function() {
    if (this.length == 0) {
        return -1;
    }
    return this[this.length - 1];
};

/**
 * const arr = [1, 2, 3];
 * arr.last(); // 3
 */