This commit is contained in:
IDONTSUDO 2023-11-20 00:48:40 +03:00
parent d70253d6a6
commit fa645dde92
51 changed files with 657 additions and 281 deletions

View file

@ -1,25 +1,18 @@
export {};
declare global {
interface Array<T> {
// @strict: The parameter is determined whether the arrays must be exactly the same in content and order of this relationship or simply follow the same requirements.
equals(array: Array<T>, strict: boolean): boolean;
}
}
export const ArrayEquals = () => {
if ([].equals == undefined) {
/* eslint-disable @typescript-eslint/no-this-alias */
export const ArrayExtensions = () => {
if ([].equals === undefined) {
// eslint-disable-next-line no-extend-native
Array.prototype.equals = function (array, strict = true) {
if (!array) return false;
if (arguments.length == 1) strict = true;
if (arguments.length === 1) strict = true;
if (this.length != array.length) return false;
if (this.length !== array.length) return false;
for (let i = 0; i < this.length; i++) {
if (this[i] instanceof Array && array[i] instanceof Array) {
if (!this[i].equals(array[i], strict)) return false;
} else if (strict && this[i] != array[i]) {
} else if (strict && this[i] !== array[i]) {
return false;
} else if (!strict) {
return this.sort().equals(array.sort(), true);
@ -28,4 +21,27 @@ export const ArrayEquals = () => {
return true;
};
}
if ([].lastElement === undefined) {
// eslint-disable-next-line no-extend-native
Array.prototype.lastElement = function () {
const instanceCheck = this;
if (instanceCheck === undefined) {
return undefined;
} else {
const instance = instanceCheck as [];
return instance[instance.length - 1];
}
};
}
if ([].isEmpty === undefined) {
// eslint-disable-next-line no-extend-native
Array.prototype.isEmpty = function () {
return this.length === 0;
};
}
if ([].isNotEmpty === undefined) {
Array.prototype.isNotEmpty = function () {
return this.length !== 0;
};
}
};