es-toolkit 0.0.1-dev.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +31 -0
  3. package/dist/array/chunk.d.ts +24 -0
  4. package/dist/array/chunk.spec.d.ts +1 -0
  5. package/dist/array/difference.d.ts +23 -0
  6. package/dist/array/difference.spec.d.ts +1 -0
  7. package/dist/array/differenceBy.d.ts +26 -0
  8. package/dist/array/differenceBy.spec.d.ts +1 -0
  9. package/dist/array/differenceWith.d.ts +22 -0
  10. package/dist/array/differenceWith.spec.d.ts +1 -0
  11. package/dist/array/drop.d.ts +16 -0
  12. package/dist/array/drop.spec.d.ts +1 -0
  13. package/dist/array/dropRight.d.ts +16 -0
  14. package/dist/array/dropRight.spec.d.ts +1 -0
  15. package/dist/array/dropRightWhile.d.ts +18 -0
  16. package/dist/array/dropRightWhile.spec.d.ts +1 -0
  17. package/dist/array/dropWhile.d.ts +18 -0
  18. package/dist/array/dropWhile.spec.d.ts +1 -0
  19. package/dist/array/groupBy.d.ts +31 -0
  20. package/dist/array/groupBy.spec.d.ts +1 -0
  21. package/dist/array/index.d.ts +30 -0
  22. package/dist/array/index.js +991 -0
  23. package/dist/array/intersection.d.ts +18 -0
  24. package/dist/array/intersection.spec.d.ts +1 -0
  25. package/dist/array/intersectionBy.d.ts +21 -0
  26. package/dist/array/intersectionBy.spec.d.ts +1 -0
  27. package/dist/array/intersectionWith.d.ts +22 -0
  28. package/dist/array/intersectionWith.spec.d.ts +1 -0
  29. package/dist/array/partition.d.ts +22 -0
  30. package/dist/array/partition.spec.d.ts +1 -0
  31. package/dist/array/sample.d.ts +14 -0
  32. package/dist/array/sample.spec.d.ts +1 -0
  33. package/dist/array/shuffle.d.ts +14 -0
  34. package/dist/array/shuffle.spec.d.ts +1 -0
  35. package/dist/array/take.d.ts +23 -0
  36. package/dist/array/take.spec.d.ts +1 -0
  37. package/dist/array/takeRight.d.ts +21 -0
  38. package/dist/array/takeRight.spec.d.ts +1 -0
  39. package/dist/array/takeRightWhile.d.ts +18 -0
  40. package/dist/array/takeRightWhile.spec.d.ts +1 -0
  41. package/dist/array/takeWhile.d.ts +19 -0
  42. package/dist/array/takeWhile.spec.d.ts +1 -0
  43. package/dist/array/union.d.ts +17 -0
  44. package/dist/array/union.spec.d.ts +1 -0
  45. package/dist/array/unionBy.d.ts +21 -0
  46. package/dist/array/unionBy.spec.d.ts +1 -0
  47. package/dist/array/unionWith.d.ts +20 -0
  48. package/dist/array/unionWith.spec.d.ts +1 -0
  49. package/dist/array/uniq.d.ts +15 -0
  50. package/dist/array/uniq.spec.d.ts +1 -0
  51. package/dist/array/uniqBy.d.ts +12 -0
  52. package/dist/array/uniqBy.spec.d.ts +1 -0
  53. package/dist/array/uniqWith.d.ts +12 -0
  54. package/dist/array/uniqWith.spec.d.ts +1 -0
  55. package/dist/array/xor.d.ts +17 -0
  56. package/dist/array/xor.spec.d.ts +1 -0
  57. package/dist/array/xorBy.d.ts +20 -0
  58. package/dist/array/xorBy.spec.d.ts +1 -0
  59. package/dist/array/xorWith.d.ts +19 -0
  60. package/dist/array/xorWith.spec.d.ts +1 -0
  61. package/dist/array/zip.d.ts +25 -0
  62. package/dist/array/zip.spec.d.ts +1 -0
  63. package/dist/array/zipWith.d.ts +32 -0
  64. package/dist/array/zipWith.spec.d.ts +1 -0
  65. package/dist/function/debounce.d.ts +24 -0
  66. package/dist/function/debounce.spec.d.ts +1 -0
  67. package/dist/function/index.d.ts +3 -0
  68. package/dist/function/index.js +112 -0
  69. package/dist/function/once.d.ts +17 -0
  70. package/dist/function/once.spec.d.ts +1 -0
  71. package/dist/function/throttle.d.ts +26 -0
  72. package/dist/function/throttle.spec.d.ts +1 -0
  73. package/dist/index.d.ts +6 -0
  74. package/dist/index.js +1514 -0
  75. package/dist/math/clamp.d.ts +19 -0
  76. package/dist/math/clamp.spec.d.ts +1 -0
  77. package/dist/math/index.d.ts +3 -0
  78. package/dist/math/index.js +148 -0
  79. package/dist/math/round.d.ts +16 -0
  80. package/dist/math/round.spec.d.ts +1 -0
  81. package/dist/math/sum.d.ts +14 -0
  82. package/dist/math/sum.spec.d.ts +1 -0
  83. package/dist/object/index.d.ts +4 -0
  84. package/dist/object/index.js +286 -0
  85. package/dist/object/omit.d.ts +16 -0
  86. package/dist/object/omit.spec.d.ts +1 -0
  87. package/dist/object/omitBy.d.ts +19 -0
  88. package/dist/object/omitBy.spec.d.ts +1 -0
  89. package/dist/object/pick.d.ts +16 -0
  90. package/dist/object/pick.spec.d.ts +1 -0
  91. package/dist/object/pickBy.d.ts +19 -0
  92. package/dist/object/pickBy.spec.d.ts +1 -0
  93. package/dist/predicate/index.d.ts +4 -0
  94. package/dist/predicate/index.js +98 -0
  95. package/dist/predicate/isNil.d.ts +20 -0
  96. package/dist/predicate/isNil.spec.d.ts +1 -0
  97. package/dist/predicate/isNotNil.d.ts +16 -0
  98. package/dist/predicate/isNotNil.spec.d.ts +1 -0
  99. package/dist/predicate/isNull.d.ts +21 -0
  100. package/dist/predicate/isNull.spec.d.ts +1 -0
  101. package/dist/predicate/isUndefined.d.ts +21 -0
  102. package/dist/predicate/isUndefined.spec.d.ts +1 -0
  103. package/dist/promise/delay.d.ts +19 -0
  104. package/dist/promise/delay.spec.d.ts +1 -0
  105. package/dist/promise/index.d.ts +1 -0
  106. package/dist/promise/index.js +29 -0
  107. package/esm/_virtual/_rollupPluginBabelHelpers.mjs +163 -0
  108. package/esm/array/_virtual/_rollupPluginBabelHelpers.mjs +78 -0
  109. package/esm/array/chunk.mjs +38 -0
  110. package/esm/array/difference.mjs +29 -0
  111. package/esm/array/differenceBy.mjs +35 -0
  112. package/esm/array/differenceWith.mjs +30 -0
  113. package/esm/array/drop.mjs +20 -0
  114. package/esm/array/dropRight.mjs +20 -0
  115. package/esm/array/dropRightWhile.mjs +26 -0
  116. package/esm/array/dropWhile.mjs +25 -0
  117. package/esm/array/groupBy.mjs +54 -0
  118. package/esm/array/index.mjs +30 -0
  119. package/esm/array/intersection.mjs +24 -0
  120. package/esm/array/intersectionBy.mjs +30 -0
  121. package/esm/array/intersectionWith.mjs +30 -0
  122. package/esm/array/partition.mjs +46 -0
  123. package/esm/array/sample.mjs +19 -0
  124. package/esm/array/shuffle.mjs +27 -0
  125. package/esm/array/take.mjs +27 -0
  126. package/esm/array/takeRight.mjs +28 -0
  127. package/esm/array/takeRightWhile.mjs +27 -0
  128. package/esm/array/takeWhile.mjs +41 -0
  129. package/esm/array/union.mjs +23 -0
  130. package/esm/array/unionBy.mjs +35 -0
  131. package/esm/array/unionWith.mjs +26 -0
  132. package/esm/array/uniq.mjs +37 -0
  133. package/esm/array/uniqBy.mjs +20 -0
  134. package/esm/array/uniqWith.mjs +39 -0
  135. package/esm/array/xor.mjs +25 -0
  136. package/esm/array/xorBy.mjs +30 -0
  137. package/esm/array/xorWith.mjs +29 -0
  138. package/esm/array/zip.mjs +52 -0
  139. package/esm/array/zipWith.mjs +54 -0
  140. package/esm/function/debounce.mjs +39 -0
  141. package/esm/function/index.mjs +3 -0
  142. package/esm/function/once.mjs +31 -0
  143. package/esm/function/throttle.mjs +38 -0
  144. package/esm/index.mjs +45 -0
  145. package/esm/math/_virtual/_rollupPluginBabelHelpers.mjs +66 -0
  146. package/esm/math/clamp.mjs +26 -0
  147. package/esm/math/index.mjs +3 -0
  148. package/esm/math/round.mjs +22 -0
  149. package/esm/math/sum.mjs +33 -0
  150. package/esm/object/_virtual/_rollupPluginBabelHelpers.mjs +151 -0
  151. package/esm/object/index.mjs +4 -0
  152. package/esm/object/omit.mjs +35 -0
  153. package/esm/object/omitBy.mjs +35 -0
  154. package/esm/object/pick.mjs +35 -0
  155. package/esm/object/pickBy.mjs +35 -0
  156. package/esm/predicate/index.mjs +4 -0
  157. package/esm/predicate/isNil.mjs +24 -0
  158. package/esm/predicate/isNotNil.mjs +20 -0
  159. package/esm/predicate/isNull.mjs +25 -0
  160. package/esm/predicate/isUndefined.mjs +25 -0
  161. package/esm/promise/delay.mjs +25 -0
  162. package/esm/promise/index.mjs +1 -0
  163. package/package.json +108 -0
@@ -0,0 +1,991 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Splits an array into smaller arrays of a specified length.
7
+ *
8
+ * This function takes an input array and divides it into multiple smaller arrays,
9
+ * each of a specified length. If the input array cannot be evenly divided,
10
+ * the final sub-array will contain the remaining elements.
11
+ *
12
+ * @template T The type of elements in the array.
13
+ * @param {T[]} arr - The array to be chunked into smaller arrays.
14
+ * @param {number} size - The size of each smaller array. Must be a positive integer.
15
+ * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.
16
+ * @throws {Error} Throws an error if `size` is not a positive integer.
17
+ *
18
+ * @example
19
+ * // Splits an array of numbers into sub-arrays of length 2
20
+ * chunk([1, 2, 3, 4, 5], 2);
21
+ * // Returns: [[1, 2], [3, 4], [5]]
22
+ *
23
+ * @example
24
+ * // Splits an array of strings into sub-arrays of length 3
25
+ * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
26
+ * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
27
+ */
28
+ function chunk(arr, size) {
29
+ if (!Number.isInteger(size) || size <= 0) {
30
+ throw new Error('Size must be an integer greater than zero.');
31
+ }
32
+ var chunkLength = Math.ceil(arr.length / size);
33
+ var result = Array(chunkLength);
34
+ for (var index = 0; index < chunkLength; index++) {
35
+ var start = index * size;
36
+ var end = start + size;
37
+ result[index] = arr.slice(start, end);
38
+ }
39
+ return result;
40
+ }
41
+
42
+ /**
43
+ * Computes the difference between two arrays.
44
+ *
45
+ * This function takes two arrays and returns a new array containing the elements
46
+ * that are present in the first array but not in the second array. It effectively
47
+ * filters out any elements from the first array that also appear in the second array.
48
+ *
49
+ * @template T
50
+ * @param {T[]} firstArr - The array from which to derive the difference. This is the primary array
51
+ * from which elements will be compared and filtered.
52
+ * @param {T[]} secondArr - The array containing elements to be excluded from the first array.
53
+ * Each element in this array will be checked against the first array, and if a match is found,
54
+ * that element will be excluded from the result.
55
+ * @returns {T[]} A new array containing the elements that are present in the first array but not
56
+ * in the second array.
57
+ *
58
+ * @example
59
+ * * const array1 = [1, 2, 3, 4, 5];
60
+ * const array2 = [2, 4];
61
+ * const result = difference(array1, array2);
62
+ * // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.
63
+ */
64
+ function difference(firstArr, secondArr) {
65
+ return firstArr.filter(function (item) {
66
+ return !secondArr.includes(item);
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Computes the difference between two arrays after mapping their elements through a provided function.
72
+ *
73
+ * This function takes two arrays and a mapper function. It returns a new array containing the elements
74
+ * that are present in the first array but not in the second array, based on the identity calculated
75
+ * by the mapper function.
76
+ *
77
+ * Essentially, it filters out any elements from the first array that, when
78
+ * mapped, match an element in the mapped version of the second array.
79
+ *
80
+ * @template T, U
81
+ * @param {T[]} firstArr - The primary array from which to derive the difference.
82
+ * @param {T[]} secondArr - The array containing elements to be excluded from the first array.
83
+ * @param {(value: T) => U} mapper - The function to map the elements of both arrays. This function
84
+ * is applied to each element in both arrays, and the comparison is made based on the mapped values.
85
+ * @returns {T[]} A new array containing the elements from the first array that do not have a corresponding
86
+ * mapped identity in the second array.
87
+ *
88
+ * @example
89
+ * * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
90
+ * const array2 = [{ id: 2 }, { id: 4 }];
91
+ * const mapper = item => item.id;
92
+ * const result = differenceBy(array1, array2, mapper);
93
+ * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.
94
+ */
95
+ function differenceBy(firstArr, secondArr, mapper) {
96
+ var mappedSecondArr = secondArr.map(function (item) {
97
+ return mapper(item);
98
+ });
99
+ return firstArr.filter(function (item) {
100
+ return !mappedSecondArr.includes(mapper(item));
101
+ });
102
+ }
103
+
104
+ /**
105
+ * Computes the difference between two arrays based on a custom equality function.
106
+ *
107
+ * This function takes two arrays and a custom comparison function. It returns a new array containing
108
+ * the elements that are present in the first array but not in the second array. The comparison to determine
109
+ * if elements are equal is made using the provided custom function.
110
+ *
111
+ * @template T
112
+ * @param {T[]} firstArr - The array from which to get the difference.
113
+ * @param {T[]} secondArr - The array containing elements to exclude from the first array.
114
+ * @param {(x: T, y: T) => boolean} areItemsEqual - A function to determine if two items are equal.
115
+ * @returns {T[]} A new array containing the elements from the first array that do not match any elements in the second array
116
+ * according to the custom equality function.
117
+ *
118
+ * @example
119
+ * * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
120
+ * const array2 = [{ id: 2 }, { id: 4 }];
121
+ * const areItemsEqual = (a, b) => a.id === b.id;
122
+ * const result = differenceWith(array1, array2, areItemsEqual);
123
+ * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
124
+ */
125
+ function differenceWith(firstArr, secondArr, areItemsEqual) {
126
+ return firstArr.filter(function (firstItem) {
127
+ return secondArr.every(function (secondItem) {
128
+ return !areItemsEqual(firstItem, secondItem);
129
+ });
130
+ });
131
+ }
132
+
133
+ /**
134
+ * Removes a specified number of elements from the beginning of an array and returns the rest.
135
+ *
136
+ * This function takes an array and a number, and returns a new array with the specified number
137
+ * of elements removed from the start.
138
+ *
139
+ * @param {T[]} arr - The array from which to drop elements.
140
+ * @param {number} itemsCount - The number of elements to drop from the beginning of the array.
141
+ * @returns {T[]} A new array with the specified number of elements removed from the start.
142
+ *
143
+ * @example
144
+ * * const array = [1, 2, 3, 4, 5];
145
+ * const result = drop(array, 2);
146
+ * // result will be [3, 4, 5] since the first two elements are dropped.
147
+ */
148
+ function drop(arr, itemsCount) {
149
+ return arr.slice(itemsCount);
150
+ }
151
+
152
+ /**
153
+ * Removes a specified number of elements from the end of an array and returns the rest.
154
+ *
155
+ * This function takes an array and a number, and returns a new array with the specified number
156
+ * of elements removed from the end.
157
+ *
158
+ * @param {T[]} arr - The array from which to drop elements.
159
+ * @param {number} itemsCount - The number of elements to drop from the end of the array.
160
+ * @returns {T[]} A new array with the specified number of elements removed from the end.
161
+ *
162
+ * @example
163
+ * * const array = [1, 2, 3, 4, 5];
164
+ * const result = dropRight(array, 2);
165
+ * // result will be [1, 2, 3] since the last two elements are dropped.
166
+ */
167
+ function dropRight(arr, itemsCount) {
168
+ return arr.slice(0, -itemsCount);
169
+ }
170
+
171
+ /**
172
+ * Removes elements from the beginning of an array until the predicate returns false.
173
+ *
174
+ * This function iterates over an array and drops elements from the start until the provided
175
+ * predicate function returns false. It then returns a new array with the remaining elements.
176
+ *
177
+ * @param {T[]} arr - The array from which to drop elements.
178
+ * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines
179
+ * whether to continue dropping elements. The function is called with each element, and dropping
180
+ * continues as long as it returns true.
181
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
182
+ *
183
+ * @example
184
+ * const array = [1, 2, 3, 4, 5];
185
+ * const result = dropWhile(array, x => x < 3);
186
+ * // result will be [3, 4, 5] since elements less than 3 are dropped.
187
+ */
188
+ function dropWhile(arr, canContinueDropping) {
189
+ var dropEndIndex = arr.findIndex(function (item) {
190
+ return !canContinueDropping(item);
191
+ });
192
+ return arr.slice(dropEndIndex);
193
+ }
194
+
195
+ /**
196
+ * Removes elements from the end of an array until the predicate returns false.
197
+ *
198
+ * This function iterates over an array from the end and drops elements until the provided
199
+ * predicate function returns false. It then returns a new array with the remaining elements.
200
+ *
201
+ * @param {T[]} arr - The array from which to drop elements.
202
+ * @param {function(item: T): boolean} canContinueDropping - A predicate function that determines
203
+ * whether to continue dropping elements. The function is called with each element from the end,
204
+ * and dropping continues as long as it returns true.
205
+ * @returns {T[]} A new array with the elements remaining after the predicate returns false.
206
+ *
207
+ * @example
208
+ * const array = [1, 2, 3, 4, 5];
209
+ * const result = dropRightWhile(array, x => x > 3);
210
+ * // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.
211
+ */
212
+ function dropRightWhile(arr, canContinueDropping) {
213
+ var reversed = arr.slice().reverse();
214
+ var dropped = dropWhile(reversed, canContinueDropping);
215
+ return dropped.slice().reverse();
216
+ }
217
+
218
+ function _toConsumableArray(arr) {
219
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
220
+ }
221
+ function _arrayWithoutHoles(arr) {
222
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
223
+ }
224
+ function _iterableToArray(iter) {
225
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
226
+ }
227
+ function _unsupportedIterableToArray(o, minLen) {
228
+ if (!o) return;
229
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
230
+ var n = Object.prototype.toString.call(o).slice(8, -1);
231
+ if (n === "Object" && o.constructor) n = o.constructor.name;
232
+ if (n === "Map" || n === "Set") return Array.from(o);
233
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
234
+ }
235
+ function _arrayLikeToArray(arr, len) {
236
+ if (len == null || len > arr.length) len = arr.length;
237
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
238
+ return arr2;
239
+ }
240
+ function _nonIterableSpread() {
241
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
242
+ }
243
+ function _createForOfIteratorHelper(o, allowArrayLike) {
244
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
245
+ if (!it) {
246
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
247
+ if (it) o = it;
248
+ var i = 0;
249
+ var F = function () {};
250
+ return {
251
+ s: F,
252
+ n: function () {
253
+ if (i >= o.length) return {
254
+ done: true
255
+ };
256
+ return {
257
+ done: false,
258
+ value: o[i++]
259
+ };
260
+ },
261
+ e: function (e) {
262
+ throw e;
263
+ },
264
+ f: F
265
+ };
266
+ }
267
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
268
+ }
269
+ var normalCompletion = true,
270
+ didErr = false,
271
+ err;
272
+ return {
273
+ s: function () {
274
+ it = it.call(o);
275
+ },
276
+ n: function () {
277
+ var step = it.next();
278
+ normalCompletion = step.done;
279
+ return step;
280
+ },
281
+ e: function (e) {
282
+ didErr = true;
283
+ err = e;
284
+ },
285
+ f: function () {
286
+ try {
287
+ if (!normalCompletion && it.return != null) it.return();
288
+ } finally {
289
+ if (didErr) throw err;
290
+ }
291
+ }
292
+ };
293
+ }
294
+
295
+ /**
296
+ * Groups the elements of an array based on a provided key-generating function.
297
+ *
298
+ * This function takes an array and a function that generates a key from each element. It returns
299
+ * an object where the keys are the generated keys and the values are arrays of elements that share
300
+ * the same key.
301
+ *
302
+ * @param {T[]} arr - The array to group.
303
+ * @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
304
+ * @returns {Record<K, T[]>} An object where each key is associated with an array of elements that
305
+ * share that key.
306
+ *
307
+ * @example
308
+ * const array = [
309
+ * { category: 'fruit', name: 'apple' },
310
+ * { category: 'fruit', name: 'banana' },
311
+ * { category: 'vegetable', name: 'carrot' }
312
+ * ];
313
+ * const result = groupBy(array, item => item.category);
314
+ * // result will be:
315
+ * // {
316
+ * // fruit: [
317
+ * // { category: 'fruit', name: 'apple' },
318
+ * // { category: 'fruit', name: 'banana' }
319
+ * // ],
320
+ * // vegetable: [
321
+ * // { category: 'vegetable', name: 'carrot' }
322
+ * // ]
323
+ * // }
324
+ */
325
+ function groupBy(arr, getKeyFromItem) {
326
+ var result = {};
327
+ var _iterator = _createForOfIteratorHelper(arr),
328
+ _step;
329
+ try {
330
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
331
+ var item = _step.value;
332
+ var key = getKeyFromItem(item);
333
+ if (result[key] == null) {
334
+ result[key] = [];
335
+ }
336
+ result[key].push(item);
337
+ }
338
+ } catch (err) {
339
+ _iterator.e(err);
340
+ } finally {
341
+ _iterator.f();
342
+ }
343
+ return result;
344
+ }
345
+
346
+ /**
347
+ * Returns the intersection of two arrays.
348
+ *
349
+ * This function takes two arrays and returns a new array containing the elements that are
350
+ * present in both arrays. It effectively filters out any elements from the first array that
351
+ * are not found in the second array.
352
+ *
353
+ * @param {T[]} firstArr - The first array to compare.
354
+ * @param {T[]} secondArr - The second array to compare.
355
+ * @returns {T[]} A new array containing the elements that are present in both arrays.
356
+ *
357
+ * @example
358
+ * const array1 = [1, 2, 3, 4, 5];
359
+ * const array2 = [3, 4, 5, 6, 7];
360
+ * const result = intersection(array1, array2);
361
+ * // result will be [3, 4, 5] since these elements are in both arrays.
362
+ */
363
+ function intersection(firstArr, secondArr) {
364
+ return firstArr.filter(function (item) {
365
+ return secondArr.includes(item);
366
+ });
367
+ }
368
+
369
+ /**
370
+ * Returns the intersection of two arrays based on a mapping function.
371
+ *
372
+ * This function takes two arrays and a mapping function. It returns a new array containing
373
+ * the elements from the first array that, when mapped using the provided function, have matching
374
+ * mapped elements in the second array. It effectively filters out any elements from the first array
375
+ * that do not have corresponding mapped values in the second array.
376
+ *
377
+ * @param {T[]} firstArr - The first array to compare.
378
+ * @param {T[]} secondArr - The second array to compare.
379
+ * @param {(item: T) => U} mapper - A function to map the elements of both arrays for comparison.
380
+ * @returns {T[]} A new array containing the elements from the first array that have corresponding mapped values in the second array.
381
+ *
382
+ * @example
383
+ * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
384
+ * const array2 = [{ id: 2 }, { id: 4 }];
385
+ * const mapper = item => item.id;
386
+ * const result = intersectionBy(array1, array2, mapper);
387
+ * // result will be [{ id: 2 }] since only this element has a matching id in both arrays.
388
+ */
389
+ function intersectionBy(firstArr, secondArr, mapper) {
390
+ var mappedSecondArr = secondArr.map(function (x) {
391
+ return mapper(x);
392
+ });
393
+ return firstArr.filter(function (item) {
394
+ return mappedSecondArr.includes(mapper(item));
395
+ });
396
+ }
397
+
398
+ /**
399
+ * Returns the intersection of two arrays based on a custom equality function.
400
+ *
401
+ * This function takes two arrays and a custom equality function. It returns a new array containing
402
+ * the elements from the first array that have matching elements in the second array, as determined
403
+ * by the custom equality function. It effectively filters out any elements from the first array that
404
+ * do not have corresponding matches in the second array according to the equality function.
405
+ *
406
+ * @param {T[]} firstArr - The first array to compare.
407
+ * @param {T[]} secondArr - The second array to compare.
408
+ * @param {(x: T, y: T) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
409
+ * This function takes two arguments, one from each array, and returns `true` if the elements are considered equal, and `false` otherwise.
410
+ * @returns {T[]} A new array containing the elements from the first array that have corresponding matches in the second array according to the custom equality function.
411
+ *
412
+ * @example
413
+ * * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
414
+ * const array2 = [{ id: 2 }, { id: 4 }];
415
+ * const areItemsEqual = (a, b) => a.id === b.id;
416
+ * const result = intersectionWith(array1, array2, areItemsEqual);
417
+ * // result will be [{ id: 2 }] since this element has a matching id in both arrays.
418
+ */
419
+ function intersectionWith(firstArr, secondArr, areItemsEqual) {
420
+ return firstArr.filter(function (firstItem) {
421
+ return secondArr.some(function (secondItem) {
422
+ return areItemsEqual(firstItem, secondItem);
423
+ });
424
+ });
425
+ }
426
+
427
+ /**
428
+ * Splits an array into two groups based on a predicate function.
429
+ *
430
+ * This function takes an array and a predicate function. It returns a tuple of two arrays:
431
+ * the first array contains elements for which the predicate function returns true, and
432
+ * the second array contains elements for which the predicate function returns false.
433
+ *
434
+ * @param {T[]} arr - The array to partition.
435
+ * @param {(value: T) => boolean} isInTruthy - A predicate function that determines
436
+ * whether an element should be placed in the truthy array. The function is called with each
437
+ * element of the array.
438
+ * @returns {[T[], T[]]} A tuple containing two arrays: the first array contains elements for
439
+ * which the predicate returned true, and the second array contains elements for which the
440
+ * predicate returned false.
441
+ *
442
+ * @example
443
+ * const array = [1, 2, 3, 4, 5];
444
+ * const isEven = x => x % 2 === 0;
445
+ * const [even, odd] = partition(array, isEven);
446
+ * // even will be [2, 4], and odd will be [1, 3, 5]
447
+ */
448
+ function partition(arr, isInTruthy) {
449
+ var truthy = [];
450
+ var falsy = [];
451
+ var _iterator = _createForOfIteratorHelper(arr),
452
+ _step;
453
+ try {
454
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
455
+ var item = _step.value;
456
+ if (isInTruthy(item)) {
457
+ truthy.push(item);
458
+ } else {
459
+ falsy.push(item);
460
+ }
461
+ }
462
+ } catch (err) {
463
+ _iterator.e(err);
464
+ } finally {
465
+ _iterator.f();
466
+ }
467
+ return [truthy, falsy];
468
+ }
469
+
470
+ /**
471
+ * Returns a random element from an array.
472
+ *
473
+ * This function takes an array and returns a single element selected randomly from the array.
474
+ *
475
+ * @param {T[]} arr - The array to sample from.
476
+ * @returns {T} A random element from the array.
477
+ *
478
+ * @example
479
+ * const array = [1, 2, 3, 4, 5];
480
+ * const randomElement = sample(array);
481
+ * // randomElement will be one of the elements from the array, selected randomly.
482
+ */
483
+ function sample(arr) {
484
+ var randomIndex = Math.floor(Math.random() * arr.length);
485
+ return arr[randomIndex];
486
+ }
487
+
488
+ /**
489
+ * Randomizes the order of elements in an array using the Fisher-Yates algorithm.
490
+ *
491
+ * This function takes an array and returns a new array with its elements shuffled in a random order.
492
+ *
493
+ * @param {T[]} arr - The array to shuffle.
494
+ * @returns {T[]} A new array with its elements shuffled in random order.
495
+ *
496
+ * @example
497
+ * const array = [1, 2, 3, 4, 5];
498
+ * const shuffledArray = shuffle(array);
499
+ * // shuffledArray will be a new array with elements of array in random order, e.g., [3, 1, 4, 5, 2]
500
+ */
501
+ function shuffle(arr) {
502
+ /**
503
+ * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
504
+ */
505
+ for (var i = arr.length - 1; i >= 1; i--) {
506
+ var j = Math.floor(Math.random() * (i + 1));
507
+ var _ref = [arr[j], arr[i]];
508
+ arr[i] = _ref[0];
509
+ arr[j] = _ref[1];
510
+ }
511
+ return arr;
512
+ }
513
+
514
+ /**
515
+ * Returns a new array containing the first `count` elements from the input array `arr`.
516
+ * If `count` is greater than the length of `arr`, the entire array is returned.
517
+ *
518
+ * @template T - Type of elements in the input array.
519
+ *
520
+ * @param {T[]} arr - The array to take elements from.
521
+ * @param {number} count - The number of elements to take.
522
+ * @returns {T[]} A new array containing the first `count` elements from `arr`.
523
+ *
524
+ * @example
525
+ * // Returns [1, 2, 3]
526
+ * take([1, 2, 3, 4, 5], 3);
527
+ *
528
+ * @example
529
+ * // Returns ['a', 'b']
530
+ * take(['a', 'b', 'c'], 2);
531
+ *
532
+ * @example
533
+ * // Returns [1, 2, 3]
534
+ * take([1, 2, 3], 5);
535
+ */
536
+ function take(arr, count) {
537
+ return arr.slice(0, count);
538
+ }
539
+
540
+ /**
541
+ * Returns a new array containing the last `count` elements from the input array `arr`.
542
+ * If `count` is greater than the length of `arr`, the entire array is returned.
543
+ *
544
+ * @param {T[]} arr - The array to take elements from.
545
+ * @param {number} count - The number of elements to take.
546
+ * @returns {T[]} A new array containing the last `count` elements from `arr`.
547
+ *
548
+ * @example
549
+ * // Returns [4, 5]
550
+ * takeRight([1, 2, 3, 4, 5], 2);
551
+ *
552
+ * @example
553
+ * // Returns ['b', 'c']
554
+ * takeRight(['a', 'b', 'c'], 2);
555
+ *
556
+ * @example
557
+ * // Returns [1, 2, 3]
558
+ * takeRight([1, 2, 3], 5);
559
+ */
560
+ function takeRight(arr, count) {
561
+ if (count === 0) {
562
+ return [];
563
+ }
564
+ return arr.slice(-count);
565
+ }
566
+
567
+ /**
568
+ * Takes elements from the end of the array while the predicate function returns `true`.
569
+ *
570
+ * @template T - Type of elements in the input array.
571
+ *
572
+ * @param {T[]} arr - The array to take elements from.
573
+ * @param {function(T): boolean} shouldContinueTaking - The function invoked per element.
574
+ * @returns {T[]} A new array containing the elements taken from the end while the predicate returns `true`.
575
+ *
576
+ * @example
577
+ * // Returns [3, 2, 1]
578
+ * takeRightWhile([5, 4, 3, 2, 1], n => n < 4);
579
+ *
580
+ * @example
581
+ * // Returns []
582
+ * takeRightWhile([1, 2, 3], n => n > 3);
583
+ */
584
+ function takeRightWhile(arr, shouldContinueTaking) {
585
+ for (var i = arr.length - 1; i >= 0; i--) {
586
+ if (!shouldContinueTaking(arr[i])) {
587
+ return arr.slice(i + 1);
588
+ }
589
+ }
590
+ return arr.slice();
591
+ }
592
+
593
+ /**
594
+ * Returns a new array containing the leading elements of the provided array
595
+ * that satisfy the provided predicate function. It stops taking elements as soon
596
+ * as an element does not satisfy the predicate.
597
+ *
598
+ * @template T - The type of elements in the array.
599
+ * @param {T[]} arr - The array to process.
600
+ * @param {(element: T) => boolean} shouldContinueTaking - The predicate function that is called with each element. Elements are included in the result as long as this function returns true.
601
+ * @returns {T[]} A new array containing the leading elements that satisfy the predicate.
602
+ *
603
+ * @example
604
+ * // Returns [1, 2]
605
+ * takeWhile([1, 2, 3, 4], x => x < 3);
606
+ *
607
+ * @example
608
+ * // Returns []
609
+ * takeWhile([1, 2, 3, 4], x => x > 3);
610
+ */
611
+ function takeWhile(arr, shouldContinueTaking) {
612
+ var result = [];
613
+ var _iterator = _createForOfIteratorHelper(arr),
614
+ _step;
615
+ try {
616
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
617
+ var item = _step.value;
618
+ if (!shouldContinueTaking(item)) {
619
+ break;
620
+ }
621
+ result.push(item);
622
+ }
623
+ } catch (err) {
624
+ _iterator.e(err);
625
+ } finally {
626
+ _iterator.f();
627
+ }
628
+ return result;
629
+ }
630
+
631
+ /**
632
+ * Creates a duplicate-free version of an array.
633
+ *
634
+ * This function takes an array and returns a new array containing only the unique values
635
+ * from the original array, preserving the order of first occurrence.
636
+ *
637
+ * @param {T[]} arr - The array to process.
638
+ * @returns {T[]} A new array with only unique values from the original array.
639
+ *
640
+ * @example
641
+ * * const array = [1, 2, 2, 3, 4, 4, 5];
642
+ * const result = uniq(array);
643
+ * // result will be [1, 2, 3, 4, 5]
644
+ */
645
+ function uniq(arr) {
646
+ var result = [];
647
+ var _iterator = _createForOfIteratorHelper(arr),
648
+ _step;
649
+ try {
650
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
651
+ var item = _step.value;
652
+ if (result.includes(item)) {
653
+ continue;
654
+ }
655
+ result.push(item);
656
+ }
657
+ } catch (err) {
658
+ _iterator.e(err);
659
+ } finally {
660
+ _iterator.f();
661
+ }
662
+ return result;
663
+ }
664
+
665
+ /**
666
+ * Creates an array of unique values from all given arrays.
667
+ *
668
+ * This function takes two arrays, merges them into a single array, and returns a new array
669
+ * containing only the unique values from the merged array.
670
+ *
671
+ * @param {T[]} arr1 - The first array to merge and filter for unique values.
672
+ * @param {T[]} arr2 - The second array to merge and filter for unique values.
673
+ * @returns {T[]} A new array of unique values.
674
+ *
675
+ * @example
676
+ * const array1 = [1, 2, 3];
677
+ * const array2 = [3, 4, 5];
678
+ * const result = union(array1, array2);
679
+ * // result will be [1, 2, 3, 4, 5]
680
+ */
681
+ function union(arr1, arr2) {
682
+ return uniq(arr1.concat(arr2));
683
+ }
684
+
685
+ /**
686
+ * Creates an array of unique values, in order, from all given arrays using a provided mapping function to determine equality.
687
+ *
688
+ * @param {T[]} arr1 - The first array.
689
+ * @param {T[]} arr2 - The second array.
690
+ * @param {function(item: T): U} mapper - The function to map array elements to comparison values.
691
+ * @returns {T[]} A new array containing the union of unique elements from `arr1` and `arr2`, based on the values returned by the mapping function.
692
+ *
693
+ * @example
694
+ * // Custom mapping function for numbers (modulo comparison)
695
+ * const moduloMapper = (x) => x % 3;
696
+ * unionBy([1, 2, 3], [4, 5, 6], moduloMapper);
697
+ * // Returns [1, 2, 3]
698
+ *
699
+ * @example
700
+ * // Custom mapping function for objects with an 'id' property
701
+ * const idMapper = (obj) => obj.id;
702
+ * unionBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], idMapper);
703
+ * // Returns [{ id: 1 }, { id: 2 }, { id: 3 }]
704
+ */
705
+ function unionBy(arr1, arr2, mapper) {
706
+ var map = new Map();
707
+ for (var _i = 0, _arr = [].concat(_toConsumableArray(arr1), _toConsumableArray(arr2)); _i < _arr.length; _i++) {
708
+ var item = _arr[_i];
709
+ var key = mapper(item);
710
+ if (!map.has(key)) {
711
+ map.set(key, item);
712
+ }
713
+ }
714
+ return _toConsumableArray(map.values());
715
+ }
716
+
717
+ /**
718
+ * The `uniqWith` function takes an array as its first argument and a 'comparator' function as the second.
719
+ *
720
+ * It evaluates the elements of the array using the comparator function, and if true is returned, it considers those elements as duplicates and removes them.
721
+ *
722
+ * @example
723
+ * ```ts
724
+ * uniqWith([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], (a, b) => );
725
+ * // [1, 2, 3, 5, 7]
726
+ * ```
727
+ */
728
+ function uniqWith(arr, areItemsEqual) {
729
+ var result = [];
730
+ var _iterator = _createForOfIteratorHelper(arr),
731
+ _step;
732
+ try {
733
+ var _loop = function _loop() {
734
+ var item = _step.value;
735
+ var isUniq = result.every(function (v) {
736
+ return !areItemsEqual(v, item);
737
+ });
738
+ if (isUniq) {
739
+ result.push(item);
740
+ }
741
+ };
742
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
743
+ _loop();
744
+ }
745
+ } catch (err) {
746
+ _iterator.e(err);
747
+ } finally {
748
+ _iterator.f();
749
+ }
750
+ return result;
751
+ }
752
+
753
+ /**
754
+ * Creates an array of unique values from two given arrays based on a custom equality function.
755
+ *
756
+ * This function takes two arrays and a custom equality function, merges the arrays, and returns
757
+ * a new array containing only the unique values as determined by the custom equality function.
758
+ *
759
+ * @param {T[]} arr1 - The first array to merge and filter for unique values.
760
+ * @param {T[]} arr2 - The second array to merge and filter for unique values.
761
+ * @param {(item1: T, item2: T) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
762
+ * It takes two arguments and returns `true` if the elements are considered equal, and `false` otherwise.
763
+ * @returns {T[]} A new array of unique values based on the custom equality function.
764
+ *
765
+ * @example
766
+ * const array1 = [{ id: 1 }, { id: 2 }];
767
+ * const array2 = [{ id: 2 }, { id: 3 }];
768
+ * const areItemsEqual = (a, b) => a.id === b.id;
769
+ * const result = unionWith(array1, array2, areItemsEqual);
770
+ * // result will be [{ id: 1 }, { id: 2 }, { id: 3 }] since { id: 2 } is considered equal in both arrays
771
+ */
772
+ function unionWith(arr1, arr2, areItemsEqual) {
773
+ return uniqWith(arr1.concat(arr2), areItemsEqual);
774
+ }
775
+
776
+ /**
777
+ * The `uniqBy` function takes an array as its first argument and a 'converter' function as the second. It maps the array elements using the converter function, then removes any duplicates.
778
+ *
779
+ * It filters out elements with the same value, meaning it does not check for duplicates in data types like Objects.
780
+ *
781
+ * @example
782
+ * ```ts
783
+ * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);
784
+ * // [1.2, 2.1, 3.3, 5.7, 7.19]
785
+ * ```
786
+ */
787
+ function uniqBy(arr, converter) {
788
+ return uniqWith(arr, function (item1, item2) {
789
+ return converter(item1) === converter(item2);
790
+ });
791
+ }
792
+
793
+ /**
794
+ * Computes the symmetric difference between two arrays. The symmetric difference is the set of elements
795
+ * which are in either of the arrays, but not in their intersection.
796
+ *
797
+ * @param {T[]} arr1 - The first array.
798
+ * @param {T[]} arr2 - The second array.
799
+ * @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both.
800
+ *
801
+ * @example
802
+ * // Returns [1, 2, 5, 6]
803
+ * xor([1, 2, 3, 4], [3, 4, 5, 6]);
804
+ *
805
+ * @example
806
+ * // Returns ['a', 'c']
807
+ * xor(['a', 'b'], ['b', 'c']);
808
+ */
809
+ function xor(arr1, arr2) {
810
+ return difference(union(arr1, arr2), intersection(arr1, arr2));
811
+ }
812
+
813
+ /**
814
+ * Computes the symmetric difference between two arrays using a custom mapping function.
815
+ * The symmetric difference is the set of elements which are in either of the arrays,
816
+ * but not in their intersection, determined by the result of the mapping function.
817
+ *
818
+ * @template T - Type of elements in the input arrays.
819
+ * @template U - Type of the values returned by the mapping function.
820
+ *
821
+ * @param {T[]} arr1 - The first array.
822
+ * @param {T[]} arr2 - The second array.
823
+ * @param {function(item: T): U} mapper - The function to map array elements to comparison values.
824
+ * @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both, based on the values returned by the mapping function.
825
+ *
826
+ * @example
827
+ * // Custom mapping function for objects with an 'id' property
828
+ * const idMapper = obj => obj.id;
829
+ * xorBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], idMapper);
830
+ * // Returns [{ id: 1 }, { id: 3 }]
831
+ */
832
+ function xorBy(arr1, arr2, mapper) {
833
+ var union = unionBy(arr1, arr2, mapper);
834
+ var intersection = intersectionBy(arr1, arr2, mapper);
835
+ return differenceBy(union, intersection, mapper);
836
+ }
837
+
838
+ /**
839
+ * Computes the symmetric difference between two arrays using a custom equality function.
840
+ * The symmetric difference is the set of elements which are in either of the arrays,
841
+ * but not in their intersection.
842
+ *
843
+ * @template T - Type of elements in the input arrays.
844
+ *
845
+ * @param {T[]} arr1 - The first array.
846
+ * @param {T[]} arr2 - The second array.
847
+ * @param {(item1: T, item2: T) => boolean} areElementsEqual - The custom equality function to compare elements.
848
+ * @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both, based on the custom equality function.
849
+ *
850
+ * @example
851
+ * // Custom equality function for objects with an 'id' property
852
+ * const areObjectsEqual = (a, b) => a.id === b.id;
853
+ * xorWith([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], areObjectsEqual);
854
+ * // Returns [{ id: 1 }, { id: 3 }]
855
+ */
856
+ function xorWith(arr1, arr2, areElementsEqual) {
857
+ var union = unionWith(arr1, arr2, areElementsEqual);
858
+ var intersection = intersectionWith(arr1, arr2, areElementsEqual);
859
+ return differenceWith(union, intersection, areElementsEqual);
860
+ }
861
+
862
+ /**
863
+ * Combines multiple arrays into a single array of tuples.
864
+ *
865
+ * This function takes multiple arrays and returns a new array where each element is a tuple
866
+ * containing the corresponding elements from the input arrays. If the input arrays are of
867
+ * different lengths, the resulting array will have the length of the longest input array,
868
+ * with undefined values for missing elements.
869
+ *
870
+ * @param {...T[][]} arrs - The arrays to zip together.
871
+ * @returns {T[][]} A new array of tuples containing the corresponding elements from the input arrays.
872
+ *
873
+ * @example
874
+ * const arr1 = [1, 2, 3];
875
+ * const arr2 = ['a', 'b', 'c'];
876
+ * const result = zip(arr1, arr2);
877
+ * // result will be [[1, 'a'], [2, 'b'], [3, 'c']]
878
+ *
879
+ * const arr3 = [true, false];
880
+ * const result2 = zip(arr1, arr2, arr3);
881
+ * // result2 will be [[1, 'a', true], [2, 'b', false], [3, 'c', undefined]]
882
+ */
883
+
884
+ function zip() {
885
+ var result = [];
886
+ for (var _len = arguments.length, arrs = new Array(_len), _key = 0; _key < _len; _key++) {
887
+ arrs[_key] = arguments[_key];
888
+ }
889
+ var maxIndex = Math.max.apply(Math, _toConsumableArray(arrs.map(function (x) {
890
+ return x.length;
891
+ })));
892
+ for (var i = 0; i < maxIndex; i++) {
893
+ var element = [];
894
+ var _iterator = _createForOfIteratorHelper(arrs),
895
+ _step;
896
+ try {
897
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
898
+ var arr = _step.value;
899
+ element.push(arr[i]);
900
+ }
901
+ } catch (err) {
902
+ _iterator.e(err);
903
+ } finally {
904
+ _iterator.f();
905
+ }
906
+ result.push(element);
907
+ }
908
+ return result;
909
+ }
910
+
911
+ /**
912
+ * Combines multiple arrays into a single array using a custom combiner function.
913
+ *
914
+ * This function takes multiple arrays and a combiner function, and returns a new array where each element
915
+ * is the result of applying the combiner function to the corresponding elements of the input arrays.
916
+ *
917
+ * @param {T[]} arr1 - The first array to zip.
918
+ * @param {U[]} [arr2] - The second array to zip (optional).
919
+ * @param {V[]} [arr3] - The third array to zip (optional).
920
+ * @param {W[]} [arr4] - The fourth array to zip (optional).
921
+ * @param {function} combine - The combiner function that takes corresponding elements from each array and returns a single value.
922
+ * @returns {R[]} A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.
923
+ *
924
+ * @example
925
+ * // Example usage with two arrays:
926
+ * const arr1 = [1, 2, 3];
927
+ * const arr2 = [4, 5, 6];
928
+ * const result = zipWith(arr1, arr2, (a, b) => a + b);
929
+ * // result will be [5, 7, 9]
930
+ *
931
+ * @example
932
+ * // Example usage with three arrays:
933
+ * const arr1 = [1, 2];
934
+ * const arr2 = [3, 4];
935
+ * const arr3 = [5, 6];
936
+ * const result = zipWith(arr1, arr2, arr3, (a, b, c) => `${a}${b}${c}`);
937
+ * // result will be [`135`, `246`]
938
+ */
939
+
940
+ function zipWith(arr1) {
941
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
942
+ rest[_key - 1] = arguments[_key];
943
+ }
944
+ var arrs = [arr1].concat(_toConsumableArray(rest.slice(0, -1)));
945
+ var combine = rest[rest.length - 1];
946
+ var result = [];
947
+ var maxIndex = Math.max.apply(Math, _toConsumableArray(arrs.map(function (arr) {
948
+ return arr.length;
949
+ })));
950
+ var _loop = function _loop(i) {
951
+ var elements = arrs.map(function (arr) {
952
+ return arr[i];
953
+ });
954
+ result.push(combine.apply(void 0, _toConsumableArray(elements)));
955
+ };
956
+ for (var i = 0; i < maxIndex; i++) {
957
+ _loop(i);
958
+ }
959
+ return result;
960
+ }
961
+
962
+ exports.chunk = chunk;
963
+ exports.difference = difference;
964
+ exports.differenceBy = differenceBy;
965
+ exports.differenceWith = differenceWith;
966
+ exports.drop = drop;
967
+ exports.dropRight = dropRight;
968
+ exports.dropRightWhile = dropRightWhile;
969
+ exports.dropWhile = dropWhile;
970
+ exports.groupBy = groupBy;
971
+ exports.intersection = intersection;
972
+ exports.intersectionBy = intersectionBy;
973
+ exports.intersectionWith = intersectionWith;
974
+ exports.partition = partition;
975
+ exports.sample = sample;
976
+ exports.shuffle = shuffle;
977
+ exports.take = take;
978
+ exports.takeRight = takeRight;
979
+ exports.takeRightWhile = takeRightWhile;
980
+ exports.takeWhile = takeWhile;
981
+ exports.union = union;
982
+ exports.unionBy = unionBy;
983
+ exports.unionWith = unionWith;
984
+ exports.uniq = uniq;
985
+ exports.uniqBy = uniqBy;
986
+ exports.uniqWith = uniqWith;
987
+ exports.xor = xor;
988
+ exports.xorBy = xorBy;
989
+ exports.xorWith = xorWith;
990
+ exports.zip = zip;
991
+ exports.zipWith = zipWith;