From 01718a10d45f9e9f52a421bbf1576556ac297674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Tue, 26 Mar 2024 08:28:37 -0300 Subject: [PATCH] core: frontend: cosmos: Add Array.last MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- core/frontend/src/cosmos.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/frontend/src/cosmos.ts b/core/frontend/src/cosmos.ts index 09b62e24b..df614f78b 100644 --- a/core/frontend/src/cosmos.ts +++ b/core/frontend/src/cosmos.ts @@ -3,6 +3,7 @@ export {} declare global { interface Array { first(): T | undefined; + last(): T | undefined; isEmpty(): boolean; } @@ -18,6 +19,11 @@ Array.prototype.first = function (this: T[]): T | undefined { return this.isEmpty() ? undefined : this[0] } +// eslint-disable-next-line +Array.prototype.last = function (this: T[]): T | undefined { + return this.at(-1) +} + // eslint-disable-next-line Array.prototype.isEmpty = function (this: T[]): boolean { return this.length === 0