Created
July 6, 2023 04:24
-
-
Save nickforce/f3bd1c370db22f305f78cd2225f75332 to your computer and use it in GitHub Desktop.
Array Prototype Last (leetcode)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.last = function() { | |
if(!this?.length) return -1; | |
return this.pop(); | |
}; | |
/** | |
* const arr = [1, 2, 3]; | |
* arr.last(); // 3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment