1 | declare global {
|
2 | interface ObjectConstructor {
|
3 | assign<T>(target:T, ...sources: any[]):T & any;
|
4 | isEqual(o1:any,o2:any):boolean
|
5 | }
|
6 |
|
7 | interface Array<T> {
|
8 | includes(element:T):boolean
|
9 | size:number
|
10 | }
|
11 |
|
12 | interface ArrayConstructor {
|
13 | isEqual(arr1:any[],arr2:any[],ignoreOrder?:boolean):boolean
|
14 | }
|
15 |
|
16 | var __filename:string
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | if (!Object.isEqual) {
|
23 | Object.isEqual = (o1:any,o2:any):boolean => {
|
24 | return o1 === o2 ||
|
25 | (o1.isEqual && o2.isEqual && o1.isEqual(o2))
|
26 | }
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | if (!Array.isEqual) {
|
33 |
|
34 | Array.isEqual = function(arr1,arr2,ignoreOrder = false) {
|
35 |
|
36 | if (arr1 === arr2) return true;
|
37 | if (!Array.isArray(arr1) || !Array.isArray(arr2)) return false;
|
38 | if (arr1.length !== arr2.length) return false;
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | if (!ignoreOrder) {
|
44 | for (var i = 0; i < arr1.length; ++i) {
|
45 | if (arr1[i] !== arr2[i]) return false;
|
46 | }
|
47 | } else {
|
48 | for (let item1 of arr1) {
|
49 | if (!arr2.find(item2 => Object.isEqual(item1,item2)))
|
50 | return false
|
51 | }
|
52 | }
|
53 | return true;
|
54 |
|
55 | }
|
56 | }
|
57 |
|
58 |
|
59 | if (!Object.getOwnPropertyDescriptor(Array.prototype,'size')) {
|
60 | Object.defineProperty(Array.prototype,'size',{
|
61 | get: function() {
|
62 | return this.length
|
63 | }
|
64 | })
|
65 | }
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | if (!Array.prototype.includes) {
|
71 | Array.prototype.includes = function(searchElement ) {
|
72 | 'use strict';
|
73 | let O = Object(this) as any;
|
74 | let len = parseInt(O.length) || 0;
|
75 | if (len === 0) {
|
76 | return false;
|
77 | }
|
78 | let n = parseInt(arguments[1]) || 0;
|
79 | let k;
|
80 | if (n >= 0) {
|
81 | k = n;
|
82 | } else {
|
83 | k = len + n;
|
84 | if (k < 0) {k = 0;}
|
85 | }
|
86 | let currentElement;
|
87 | while (k < len) {
|
88 | currentElement = O[k];
|
89 | if (searchElement === currentElement ||
|
90 | (searchElement !== searchElement && currentElement !== currentElement)) {
|
91 | return true;
|
92 | }
|
93 | k++;
|
94 | }
|
95 | return false;
|
96 | };
|
97 | }
|
98 |
|
99 | export {} |
\ | No newline at end of file |