| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- System.register(["cc"], function (_export, _context) {
- "use strict";
- var _cclegacy, _crd;
- return {
- setters: [function (_cc) {
- _cclegacy = _cc.cclegacy;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "2696fVV0U1BcotwtuSW7qe9", "ArrayExt", undefined);
- // @ts-ignore
- !Array.prototype.__cc_extended && Object.defineProperties(Array.prototype, {
- remove: {
- value: function (filter) {
- if (typeof filter == 'function') {
- for (let i = this.length - 1; i > -1; --i) {
- filter(this[i], i, this) && this.splice(i, 1);
- }
- } else {
- for (let i = this.length - 1; i > -1; --i) {
- this[i] === filter && this.splice(i, 1);
- }
- }
- return this;
- }
- },
- removeOne: {
- value: function (filter) {
- if (typeof filter == 'function') {
- for (let i = 0; i < this.length; ++i) {
- if (filter(this[i], i, this)) {
- this.splice(i, 1);
- return this;
- }
- }
- } else {
- for (let i = 0; i < this.length; ++i) {
- if (this[i] === filter) {
- this.splice(i, 1);
- return this;
- }
- }
- }
- return this;
- }
- },
- random: {
- value: function () {
- let element = this[Math.floor(Math.random() * this.length)];
- return element;
- }
- },
- fastRemoveAt: {
- value: function (index) {
- const length = this.length;
- if (index < 0 || index >= length) {
- return null;
- }
- let res = this[index];
- this[index] = this[length - 1];
- this.length = length - 1;
- return res;
- }
- },
- fastRemove: {
- value: function (value) {
- const index = this.indexOf(value);
- if (index >= 0) {
- this[index] = this[this.length - 1];
- --this.length;
- return true;
- }
- return false;
- }
- },
- first: {
- value: function () {
- return this.length ? this[0] : null;
- }
- },
- last: {
- value: function () {
- return this.length ? this[this.length - 1] : null;
- }
- },
- max: {
- value: function (mapper) {
- if (!this.length) {
- return null;
- }
- function _max(a, b) {
- return a > b ? a : b;
- }
- if (typeof mapper == 'function') {
- let max = mapper(this[0], 0, this);
- for (let i = 1; i < this.length; ++i) {
- let temp = mapper(this[i], i, this);
- max = temp > max ? temp : max;
- }
- return max;
- } else {
- return this.reduce(function (prev, cur) {
- return _max(prev, cur);
- });
- }
- }
- },
- min: {
- value: function (mapper) {
- if (!this.length) {
- return null;
- }
- function _min(a, b) {
- return a < b ? a : b;
- }
- if (typeof mapper == 'function') {
- let min = mapper(this[0], 0, this);
- for (let i = 1; i < this.length; ++i) {
- let temp = mapper(this[i], i, this);
- min = temp < min ? temp : min;
- }
- return min;
- } else {
- return this.reduce(function (prev, cur) {
- return _min(prev, cur);
- });
- }
- }
- },
- distinct: {
- value: function () {
- return this.filter(function (v, i, arr) {
- return arr.indexOf(v) === i;
- });
- }
- },
- filterIndex: {
- value: function (filter) {
- let output = [];
- for (let i = 0; i < this.length; ++i) {
- if (filter(this[i], i, this)) {
- output.push(i);
- }
- }
- return output;
- }
- },
- count: {
- value: function (filter) {
- let result = 0;
- for (let i = 0; i < this.length; ++i) {
- if (filter(this[i], i, this)) {
- ++result;
- }
- }
- return result;
- }
- },
- sum: {
- value: function (mapper) {
- let result = 0;
- for (let i = 0; i < this.length; ++i) {
- result += mapper ? mapper(this[i], i, this) : this[i];
- }
- return result;
- }
- },
- average: {
- value: function (mapper) {
- return this.sum(mapper) / this.length;
- }
- },
- orderBy: {
- value: function () {
- let mappers = [];
- for (let _i = 0; _i < arguments.length; _i++) {
- mappers[_i] = arguments[_i];
- }
- return this.slice().sort(function (a, b) {
- for (let i = 0; i < mappers.length; ++i) {
- let va = mappers[i](a);
- let vb = mappers[i](b);
- if (va > vb) {
- return 1;
- } else if (va < vb) {
- return -1;
- }
- }
- return 0;
- });
- }
- },
- orderByDesc: {
- value: function () {
- let mappers = [];
- for (let _i = 0; _i < arguments.length; _i++) {
- mappers[_i] = arguments[_i];
- }
- return this.slice().sort(function (a, b) {
- for (let i = 0; i < mappers.length; ++i) {
- let va = mappers[i](a);
- let vb = mappers[i](b);
- if (va > vb) {
- return -1;
- } else if (va < vb) {
- return 1;
- }
- }
- return 0;
- });
- }
- },
- binarySearch: {
- value: function (value, keyMapper) {
- let low = 0,
- high = this.length - 1;
- while (low <= high) {
- let mid = (high + low) / 2 | 0;
- let midValue = keyMapper ? keyMapper(this[mid]) : this[mid];
- if (value === midValue) {
- return mid;
- } else if (value > midValue) {
- low = mid + 1;
- } else if (value < midValue) {
- high = mid - 1;
- }
- }
- return -1;
- }
- },
- binaryInsert: {
- value: function (item, keyMapper, unique) {
- if (typeof keyMapper == 'boolean') {
- unique = keyMapper;
- keyMapper = undefined;
- }
- let low = 0,
- high = this.length - 1;
- let mid = NaN;
- let itemValue = keyMapper ? keyMapper(item) : item;
- while (low <= high) {
- mid = (high + low) / 2 | 0;
- let midValue = keyMapper ? keyMapper(this[mid]) : this[mid];
- if (itemValue === midValue) {
- if (unique) {
- return mid;
- } else {
- break;
- }
- } else if (itemValue > midValue) {
- low = mid + 1;
- } else if (itemValue < midValue) {
- high = mid - 1;
- }
- }
- let index = low > mid ? mid + 1 : mid;
- this.splice(index, 0, item);
- return index;
- }
- },
- binaryDistinct: {
- value: function (keyMapper) {
- return this.filter(function (v, i, arr) {
- return arr.binarySearch(v, keyMapper) === i;
- });
- }
- },
- findLast: {
- value: function (predicate) {
- for (let i = this.length - 1; i > -1; --i) {
- if (predicate(this[i], i, this)) {
- return this[i];
- }
- }
- return undefined;
- }
- },
- findLastIndex: {
- value: function (predicate) {
- for (let i = this.length - 1; i > -1; --i) {
- if (predicate(this[i], i, this)) {
- return i;
- }
- }
- return -1;
- }
- },
- groupBy: {
- value: function (grouper) {
- let group = this.reduce(function (prev, next) {
- let groupKey = grouper(next);
- if (!prev[groupKey]) {
- prev[groupKey] = [];
- }
- prev[groupKey].push(next);
- return prev;
- }, {});
- return Object.keys(group).map(function (key) {
- let arr = group[key];
- arr.key = key;
- return arr;
- });
- }
- },
- __cc_extended: {
- value: true
- }
- });
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=33f1233b7126baf8f1d1fec60de56a478e42086e.js.map
|