1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | Array.prototype.isEmpty = function () {
|
11 | return this.length === 0;
|
12 | };
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | Array.prototype.exists = function (item) {
|
20 | return this.indexOf(item) !== -1;
|
21 | };
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | Array.prototype.first = function () {
|
28 | if (this.length === 0) {
|
29 | throw "Array index out of range: 0";
|
30 | }
|
31 | return this[0];
|
32 | };
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | Array.prototype.last = function () {
|
39 | if (this.length === 0) {
|
40 | throw "Array index out of range: 0";
|
41 | }
|
42 | return this[this.length - 1];
|
43 | };
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | Array.prototype.each = Array.prototype.forEach;
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | Array.prototype.size = function () {
|
57 | return this.length;
|
58 | };
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | Array.prototype.merge = Array.prototype.concat;
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | Array.prototype.compact = function () {
|
71 | return this.filter(function (value) { return Object.isUndefinedOrNull(value); });
|
72 | };
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | Array.prototype.unique = function () {
|
79 | var temp = new Array();
|
80 | return this.filter(function (v) {
|
81 | var ret = temp.includes(v) === false;
|
82 | temp.push(v);
|
83 | return ret;
|
84 | });
|
85 | };
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | Array.prototype.without = function () {
|
93 | var values = [];
|
94 | for (var _i = 0; _i < arguments.length; _i++) {
|
95 | values[_i] = arguments[_i];
|
96 | }
|
97 | return this.filter(function (v) {
|
98 | return values.includes(v) === false;
|
99 | });
|
100 | };
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | Array.prototype.clone = function () {
|
107 | return this.slice(0);
|
108 | };
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | Array.prototype.clear = function () {
|
115 | this.length = 0;
|
116 | return this;
|
117 | };
|
118 |
|
\ | No newline at end of file |