add palindrome, reverse and loop function to base array

This commit is contained in:
2023-08-23 16:04:31 +02:00
parent 2ca6e8ee31
commit a78e153d1c

View File

@ -23,15 +23,20 @@ interface ControlChange {
} }
// @ts-ignore // @ts-ignore
Array.prototype.loop = function (index) { Array.prototype.palindrome = function (index) {
return this[index % this.length]; 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 // @ts-ignore
Array.prototype.random = function (index) { Array.prototype.random = function (index) {
return this[Math.floor(Math.random() * this.length)]; return this[Math.floor(Math.random() * this.length)];
}; };
// @ts-ignore // @ts-ignore
Array.prototype.loop = function (index) {
return this[index % this.length];
};
// @ts-ignore
Array.prototype.rand = Array.prototype.random; Array.prototype.rand = Array.prototype.random;
/** /**