From 5f5c287bd7b7e6c61275116a703ff34d1bc543a8 Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:44:09 -0500 Subject: [PATCH] Time: 49 ms (65.84%), Space: 48.5 MB (76.08%) - LeetHub --- .../2619-array-prototype-last.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 2619-array-prototype-last/2619-array-prototype-last.js diff --git a/2619-array-prototype-last/2619-array-prototype-last.js b/2619-array-prototype-last/2619-array-prototype-last.js new file mode 100644 index 0000000..3de4116 --- /dev/null +++ b/2619-array-prototype-last/2619-array-prototype-last.js @@ -0,0 +1,11 @@ +/** + * @return {null|boolean|number|string|Array|Object} + */ +Array.prototype.last = function() { + return this.length === 0 ? -1 : this[this.length - 1] +}; + +/** + * const arr = [1, 2, 3]; + * arr.last(); // 3 + */ \ No newline at end of file