diff --git a/solution/2600-2699/2619.Array Prototype Last/README.md b/solution/2600-2699/2619.Array Prototype Last/README.md index 9978418fd63e1..b03be9ad7ba7e 100644 --- a/solution/2600-2699/2619.Array Prototype Last/README.md +++ b/solution/2600-2699/2619.Array Prototype Last/README.md @@ -54,13 +54,15 @@ declare global { } Array.prototype.last = function () { - return this[this.length - 1] ?? -1; + return this.length ? this.at(-1) : -1; }; /** * const arr = [1, 2, 3]; * arr.last(); // 3 */ + +export {}; ``` ### **...** diff --git a/solution/2600-2699/2619.Array Prototype Last/README_EN.md b/solution/2600-2699/2619.Array Prototype Last/README_EN.md index c27ca6b7f7fac..24d7910687a29 100644 --- a/solution/2600-2699/2619.Array Prototype Last/README_EN.md +++ b/solution/2600-2699/2619.Array Prototype Last/README_EN.md @@ -46,13 +46,15 @@ declare global { } Array.prototype.last = function () { - return this[this.length - 1] ?? -1; + return this.length ? this.at(-1) : -1; }; /** * const arr = [1, 2, 3]; * arr.last(); // 3 */ + +export {}; ``` ### **...** diff --git a/solution/2600-2699/2619.Array Prototype Last/Solution.ts b/solution/2600-2699/2619.Array Prototype Last/Solution.ts index a39d73412f8da..e12c4e7681a75 100644 --- a/solution/2600-2699/2619.Array Prototype Last/Solution.ts +++ b/solution/2600-2699/2619.Array Prototype Last/Solution.ts @@ -5,10 +5,12 @@ declare global { } Array.prototype.last = function () { - return this[this.length - 1] ?? -1; + return this.length ? this.at(-1) : -1; }; /** * const arr = [1, 2, 3]; * arr.last(); // 3 */ + +export {};