From a78e153d1c7d60b2a67df7039659295777573d14 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Wed, 23 Aug 2023 16:04:31 +0200 Subject: [PATCH] add palindrome, reverse and loop function to base array --- src/API.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/API.ts b/src/API.ts index 1cccb37..324f453 100644 --- a/src/API.ts +++ b/src/API.ts @@ -23,15 +23,20 @@ interface ControlChange { } // @ts-ignore -Array.prototype.loop = function (index) { - return this[index % this.length]; +Array.prototype.palindrome = function (index) { + let left_to_right = Array.from(this); + let right_to_left = Array.from(this.reverse()); + return left_to_right.concat(right_to_left); }; - // @ts-ignore Array.prototype.random = function (index) { return this[Math.floor(Math.random() * this.length)]; }; // @ts-ignore +Array.prototype.loop = function (index) { + return this[index % this.length]; +}; +// @ts-ignore Array.prototype.rand = Array.prototype.random; /**