11df1452bdaa5953b74d527295fa94a133c093d1.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, _crd;
  4. return {
  5. setters: [function (_cc) {
  6. _cclegacy = _cc.cclegacy;
  7. }],
  8. execute: function () {
  9. _crd = true;
  10. _cclegacy._RF.push({}, "2696fVV0U1BcotwtuSW7qe9", "ArrayExt", undefined);
  11. // @ts-ignore
  12. !Array.prototype.__cc_extended && Object.defineProperties(Array.prototype, {
  13. remove: {
  14. value: function (filter) {
  15. if (typeof filter == 'function') {
  16. for (let i = this.length - 1; i > -1; --i) {
  17. filter(this[i], i, this) && this.splice(i, 1);
  18. }
  19. } else {
  20. for (let i = this.length - 1; i > -1; --i) {
  21. this[i] === filter && this.splice(i, 1);
  22. }
  23. }
  24. return this;
  25. }
  26. },
  27. removeOne: {
  28. value: function (filter) {
  29. if (typeof filter == 'function') {
  30. for (let i = 0; i < this.length; ++i) {
  31. if (filter(this[i], i, this)) {
  32. this.splice(i, 1);
  33. return this;
  34. }
  35. }
  36. } else {
  37. for (let i = 0; i < this.length; ++i) {
  38. if (this[i] === filter) {
  39. this.splice(i, 1);
  40. return this;
  41. }
  42. }
  43. }
  44. return this;
  45. }
  46. },
  47. random: {
  48. value: function () {
  49. let element = this[Math.floor(Math.random() * this.length)];
  50. return element;
  51. }
  52. },
  53. fastRemoveAt: {
  54. value: function (index) {
  55. const length = this.length;
  56. if (index < 0 || index >= length) {
  57. return null;
  58. }
  59. let res = this[index];
  60. this[index] = this[length - 1];
  61. this.length = length - 1;
  62. return res;
  63. }
  64. },
  65. fastRemove: {
  66. value: function (value) {
  67. const index = this.indexOf(value);
  68. if (index >= 0) {
  69. this[index] = this[this.length - 1];
  70. --this.length;
  71. return true;
  72. }
  73. return false;
  74. }
  75. },
  76. first: {
  77. value: function () {
  78. return this.length ? this[0] : null;
  79. }
  80. },
  81. last: {
  82. value: function () {
  83. return this.length ? this[this.length - 1] : null;
  84. }
  85. },
  86. max: {
  87. value: function (mapper) {
  88. if (!this.length) {
  89. return null;
  90. }
  91. function _max(a, b) {
  92. return a > b ? a : b;
  93. }
  94. if (typeof mapper == 'function') {
  95. let max = mapper(this[0], 0, this);
  96. for (let i = 1; i < this.length; ++i) {
  97. let temp = mapper(this[i], i, this);
  98. max = temp > max ? temp : max;
  99. }
  100. return max;
  101. } else {
  102. return this.reduce(function (prev, cur) {
  103. return _max(prev, cur);
  104. });
  105. }
  106. }
  107. },
  108. min: {
  109. value: function (mapper) {
  110. if (!this.length) {
  111. return null;
  112. }
  113. function _min(a, b) {
  114. return a < b ? a : b;
  115. }
  116. if (typeof mapper == 'function') {
  117. let min = mapper(this[0], 0, this);
  118. for (let i = 1; i < this.length; ++i) {
  119. let temp = mapper(this[i], i, this);
  120. min = temp < min ? temp : min;
  121. }
  122. return min;
  123. } else {
  124. return this.reduce(function (prev, cur) {
  125. return _min(prev, cur);
  126. });
  127. }
  128. }
  129. },
  130. distinct: {
  131. value: function () {
  132. return this.filter(function (v, i, arr) {
  133. return arr.indexOf(v) === i;
  134. });
  135. }
  136. },
  137. filterIndex: {
  138. value: function (filter) {
  139. let output = [];
  140. for (let i = 0; i < this.length; ++i) {
  141. if (filter(this[i], i, this)) {
  142. output.push(i);
  143. }
  144. }
  145. return output;
  146. }
  147. },
  148. count: {
  149. value: function (filter) {
  150. let result = 0;
  151. for (let i = 0; i < this.length; ++i) {
  152. if (filter(this[i], i, this)) {
  153. ++result;
  154. }
  155. }
  156. return result;
  157. }
  158. },
  159. sum: {
  160. value: function (mapper) {
  161. let result = 0;
  162. for (let i = 0; i < this.length; ++i) {
  163. result += mapper ? mapper(this[i], i, this) : this[i];
  164. }
  165. return result;
  166. }
  167. },
  168. average: {
  169. value: function (mapper) {
  170. return this.sum(mapper) / this.length;
  171. }
  172. },
  173. orderBy: {
  174. value: function () {
  175. let mappers = [];
  176. for (let _i = 0; _i < arguments.length; _i++) {
  177. mappers[_i] = arguments[_i];
  178. }
  179. return this.slice().sort(function (a, b) {
  180. for (let i = 0; i < mappers.length; ++i) {
  181. let va = mappers[i](a);
  182. let vb = mappers[i](b);
  183. if (va > vb) {
  184. return 1;
  185. } else if (va < vb) {
  186. return -1;
  187. }
  188. }
  189. return 0;
  190. });
  191. }
  192. },
  193. orderByDesc: {
  194. value: function () {
  195. let mappers = [];
  196. for (let _i = 0; _i < arguments.length; _i++) {
  197. mappers[_i] = arguments[_i];
  198. }
  199. return this.slice().sort(function (a, b) {
  200. for (let i = 0; i < mappers.length; ++i) {
  201. let va = mappers[i](a);
  202. let vb = mappers[i](b);
  203. if (va > vb) {
  204. return -1;
  205. } else if (va < vb) {
  206. return 1;
  207. }
  208. }
  209. return 0;
  210. });
  211. }
  212. },
  213. binarySearch: {
  214. value: function (value, keyMapper) {
  215. let low = 0,
  216. high = this.length - 1;
  217. while (low <= high) {
  218. let mid = (high + low) / 2 | 0;
  219. let midValue = keyMapper ? keyMapper(this[mid]) : this[mid];
  220. if (value === midValue) {
  221. return mid;
  222. } else if (value > midValue) {
  223. low = mid + 1;
  224. } else if (value < midValue) {
  225. high = mid - 1;
  226. }
  227. }
  228. return -1;
  229. }
  230. },
  231. binaryInsert: {
  232. value: function (item, keyMapper, unique) {
  233. if (typeof keyMapper == 'boolean') {
  234. unique = keyMapper;
  235. keyMapper = undefined;
  236. }
  237. let low = 0,
  238. high = this.length - 1;
  239. let mid = NaN;
  240. let itemValue = keyMapper ? keyMapper(item) : item;
  241. while (low <= high) {
  242. mid = (high + low) / 2 | 0;
  243. let midValue = keyMapper ? keyMapper(this[mid]) : this[mid];
  244. if (itemValue === midValue) {
  245. if (unique) {
  246. return mid;
  247. } else {
  248. break;
  249. }
  250. } else if (itemValue > midValue) {
  251. low = mid + 1;
  252. } else if (itemValue < midValue) {
  253. high = mid - 1;
  254. }
  255. }
  256. let index = low > mid ? mid + 1 : mid;
  257. this.splice(index, 0, item);
  258. return index;
  259. }
  260. },
  261. binaryDistinct: {
  262. value: function (keyMapper) {
  263. return this.filter(function (v, i, arr) {
  264. return arr.binarySearch(v, keyMapper) === i;
  265. });
  266. }
  267. },
  268. findLast: {
  269. value: function (predicate) {
  270. for (let i = this.length - 1; i > -1; --i) {
  271. if (predicate(this[i], i, this)) {
  272. return this[i];
  273. }
  274. }
  275. return undefined;
  276. }
  277. },
  278. findLastIndex: {
  279. value: function (predicate) {
  280. for (let i = this.length - 1; i > -1; --i) {
  281. if (predicate(this[i], i, this)) {
  282. return i;
  283. }
  284. }
  285. return -1;
  286. }
  287. },
  288. groupBy: {
  289. value: function (grouper) {
  290. let group = this.reduce(function (prev, next) {
  291. let groupKey = grouper(next);
  292. if (!prev[groupKey]) {
  293. prev[groupKey] = [];
  294. }
  295. prev[groupKey].push(next);
  296. return prev;
  297. }, {});
  298. return Object.keys(group).map(function (key) {
  299. let arr = group[key];
  300. arr.key = key;
  301. return arr;
  302. });
  303. }
  304. },
  305. __cc_extended: {
  306. value: true
  307. }
  308. });
  309. _cclegacy._RF.pop();
  310. _crd = false;
  311. }
  312. };
  313. });
  314. //# sourceMappingURL=11df1452bdaa5953b74d527295fa94a133c093d1.js.map