es-toolkit 0.0.1 → 1.0.0-dev.19

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 (236) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +31 -0
  3. package/dist/array/chunk.d.ts +21 -5
  4. package/dist/array/difference.d.ts +20 -4
  5. package/dist/array/differenceBy.d.ts +23 -5
  6. package/dist/array/differenceWith.d.ts +19 -5
  7. package/dist/array/drop.d.ts +13 -4
  8. package/dist/array/dropRight.d.ts +13 -4
  9. package/dist/array/dropRightWhile.d.ts +15 -4
  10. package/dist/array/dropWhile.d.ts +15 -4
  11. package/dist/array/groupBy.d.ts +31 -1
  12. package/dist/array/groupBy.spec.d.ts +1 -0
  13. package/dist/array/index.js +437 -224
  14. package/dist/array/intersection.d.ts +13 -6
  15. package/dist/array/intersectionBy.d.ts +17 -8
  16. package/dist/array/intersectionWith.d.ts +18 -8
  17. package/dist/array/partition.d.ts +19 -5
  18. package/dist/array/sample.d.ts +10 -3
  19. package/dist/array/shuffle.d.ts +11 -4
  20. package/dist/array/takeRight.d.ts +0 -2
  21. package/dist/array/union.d.ts +13 -6
  22. package/dist/array/unionBy.d.ts +0 -3
  23. package/dist/array/unionWith.d.ts +15 -9
  24. package/dist/array/uniq.d.ts +9 -8
  25. package/dist/array/xor.d.ts +0 -2
  26. package/dist/array/zip.d.ts +18 -6
  27. package/dist/array/zipWith.d.ts +26 -3
  28. package/dist/function/debounce.d.ts +4 -4
  29. package/dist/function/index.js +4 -5
  30. package/dist/function/once.d.ts +0 -1
  31. package/dist/index.js +651 -248
  32. package/dist/math/clamp.d.ts +16 -8
  33. package/dist/math/index.js +114 -29
  34. package/dist/math/round.d.ts +11 -8
  35. package/dist/math/sum.d.ts +10 -9
  36. package/dist/object/index.js +122 -12
  37. package/dist/object/omit.d.ts +13 -4
  38. package/dist/object/omitBy.d.ts +19 -1
  39. package/dist/object/omitBy.spec.d.ts +1 -0
  40. package/dist/object/pick.d.ts +13 -4
  41. package/dist/object/pickBy.d.ts +19 -1
  42. package/dist/object/pickBy.spec.d.ts +1 -0
  43. package/dist/predicate/index.js +58 -10
  44. package/dist/predicate/isNil.d.ts +17 -3
  45. package/dist/predicate/isNotNil.d.ts +7 -3
  46. package/dist/predicate/isNull.d.ts +17 -2
  47. package/dist/predicate/isUndefined.d.ts +17 -2
  48. package/dist/promise/delay.d.ts +17 -4
  49. package/dist/promise/index.js +16 -3
  50. package/esm/array/_virtual/_rollupPluginBabelHelpers.mjs +1 -37
  51. package/esm/array/chunk.mjs +28 -25
  52. package/esm/array/difference.mjs +20 -4
  53. package/esm/array/differenceBy.mjs +23 -5
  54. package/esm/array/differenceWith.mjs +19 -5
  55. package/esm/array/drop.mjs +13 -4
  56. package/esm/array/dropRight.mjs +13 -4
  57. package/esm/array/dropRightWhile.mjs +15 -4
  58. package/esm/array/dropWhile.mjs +15 -4
  59. package/esm/array/groupBy.mjs +51 -2
  60. package/esm/array/intersection.mjs +13 -6
  61. package/esm/array/intersectionBy.mjs +17 -8
  62. package/esm/array/intersectionWith.mjs +18 -8
  63. package/esm/array/partition.mjs +19 -5
  64. package/esm/array/sample.mjs +10 -3
  65. package/esm/array/shuffle.mjs +12 -5
  66. package/esm/array/takeRight.mjs +0 -2
  67. package/esm/array/union.mjs +14 -10
  68. package/esm/array/unionBy.mjs +0 -3
  69. package/esm/array/unionWith.mjs +16 -11
  70. package/esm/array/uniq.mjs +28 -9
  71. package/esm/array/xor.mjs +0 -2
  72. package/esm/array/zip.mjs +18 -6
  73. package/esm/array/zipWith.mjs +26 -3
  74. package/esm/function/debounce.mjs +4 -4
  75. package/esm/function/once.mjs +0 -1
  76. package/esm/math/_virtual/_rollupPluginBabelHelpers.mjs +66 -0
  77. package/esm/math/clamp.mjs +15 -7
  78. package/esm/math/round.mjs +11 -8
  79. package/esm/math/sum.mjs +25 -14
  80. package/esm/object/_virtual/_rollupPluginBabelHelpers.mjs +37 -1
  81. package/esm/object/omit.mjs +13 -4
  82. package/esm/object/omitBy.mjs +32 -2
  83. package/esm/object/pick.mjs +13 -4
  84. package/esm/object/pickBy.mjs +32 -2
  85. package/esm/predicate/isNil.mjs +17 -3
  86. package/esm/predicate/isNotNil.mjs +7 -3
  87. package/esm/predicate/isNull.mjs +17 -2
  88. package/esm/predicate/isUndefined.mjs +17 -2
  89. package/esm/promise/delay.mjs +16 -3
  90. package/package.json +17 -3
  91. package/.vscode/extensions.json +0 -7
  92. package/.vscode/settings.json +0 -10
  93. package/.yarn/sdks/eslint/bin/eslint.js +0 -20
  94. package/.yarn/sdks/eslint/lib/api.js +0 -20
  95. package/.yarn/sdks/eslint/lib/unsupported-api.js +0 -20
  96. package/.yarn/sdks/eslint/package.json +0 -14
  97. package/.yarn/sdks/integrations.yml +0 -5
  98. package/.yarn/sdks/prettier/bin/prettier.cjs +0 -20
  99. package/.yarn/sdks/prettier/index.cjs +0 -20
  100. package/.yarn/sdks/prettier/package.json +0 -7
  101. package/.yarn/sdks/typescript/bin/tsc +0 -20
  102. package/.yarn/sdks/typescript/bin/tsserver +0 -20
  103. package/.yarn/sdks/typescript/lib/tsc.js +0 -20
  104. package/.yarn/sdks/typescript/lib/tsserver.js +0 -225
  105. package/.yarn/sdks/typescript/lib/tsserverlibrary.js +0 -225
  106. package/.yarn/sdks/typescript/lib/typescript.js +0 -20
  107. package/.yarn/sdks/typescript/package.json +0 -10
  108. package/babel.config.js +0 -6
  109. package/coverage/.tmp/coverage-0.json +0 -1
  110. package/coverage/.tmp/coverage-1.json +0 -1
  111. package/coverage/.tmp/coverage-10.json +0 -1
  112. package/coverage/.tmp/coverage-11.json +0 -1
  113. package/coverage/.tmp/coverage-12.json +0 -1
  114. package/coverage/.tmp/coverage-13.json +0 -1
  115. package/coverage/.tmp/coverage-14.json +0 -1
  116. package/coverage/.tmp/coverage-15.json +0 -1
  117. package/coverage/.tmp/coverage-16.json +0 -1
  118. package/coverage/.tmp/coverage-17.json +0 -1
  119. package/coverage/.tmp/coverage-18.json +0 -1
  120. package/coverage/.tmp/coverage-19.json +0 -1
  121. package/coverage/.tmp/coverage-2.json +0 -1
  122. package/coverage/.tmp/coverage-20.json +0 -1
  123. package/coverage/.tmp/coverage-21.json +0 -1
  124. package/coverage/.tmp/coverage-22.json +0 -1
  125. package/coverage/.tmp/coverage-23.json +0 -1
  126. package/coverage/.tmp/coverage-24.json +0 -1
  127. package/coverage/.tmp/coverage-25.json +0 -1
  128. package/coverage/.tmp/coverage-26.json +0 -1
  129. package/coverage/.tmp/coverage-27.json +0 -1
  130. package/coverage/.tmp/coverage-28.json +0 -1
  131. package/coverage/.tmp/coverage-29.json +0 -1
  132. package/coverage/.tmp/coverage-3.json +0 -1
  133. package/coverage/.tmp/coverage-30.json +0 -1
  134. package/coverage/.tmp/coverage-4.json +0 -1
  135. package/coverage/.tmp/coverage-5.json +0 -1
  136. package/coverage/.tmp/coverage-6.json +0 -1
  137. package/coverage/.tmp/coverage-7.json +0 -1
  138. package/coverage/.tmp/coverage-8.json +0 -1
  139. package/coverage/.tmp/coverage-9.json +0 -1
  140. package/rollup.config.js +0 -5
  141. package/src/array/chunk.spec.ts +0 -27
  142. package/src/array/chunk.ts +0 -24
  143. package/src/array/difference.spec.ts +0 -10
  144. package/src/array/difference.ts +0 -11
  145. package/src/array/differenceBy.spec.ts +0 -9
  146. package/src/array/differenceBy.ts +0 -14
  147. package/src/array/differenceWith.spec.ts +0 -8
  148. package/src/array/differenceWith.ts +0 -14
  149. package/src/array/drop.spec.ts +0 -9
  150. package/src/array/drop.ts +0 -9
  151. package/src/array/dropRight.spec.ts +0 -9
  152. package/src/array/dropRight.ts +0 -9
  153. package/src/array/dropRightWhile.spec.ts +0 -16
  154. package/src/array/dropRightWhile.ts +0 -13
  155. package/src/array/dropWhile.spec.ts +0 -14
  156. package/src/array/dropWhile.ts +0 -10
  157. package/src/array/groupBy.ts +0 -3
  158. package/src/array/index.ts +0 -30
  159. package/src/array/intersection.spec.ts +0 -11
  160. package/src/array/intersection.ts +0 -15
  161. package/src/array/intersectionBy.spec.ts +0 -9
  162. package/src/array/intersectionBy.ts +0 -18
  163. package/src/array/intersectionWith.spec.ts +0 -9
  164. package/src/array/intersectionWith.ts +0 -18
  165. package/src/array/partition.spec.ts +0 -23
  166. package/src/array/partition.ts +0 -21
  167. package/src/array/sample.spec.ts +0 -11
  168. package/src/array/sample.ts +0 -10
  169. package/src/array/shuffle.spec.ts +0 -11
  170. package/src/array/shuffle.ts +0 -18
  171. package/src/array/take.spec.ts +0 -25
  172. package/src/array/take.ts +0 -25
  173. package/src/array/takeRight.spec.ts +0 -25
  174. package/src/array/takeRight.ts +0 -29
  175. package/src/array/takeRightWhile.spec.ts +0 -16
  176. package/src/array/takeRightWhile.ts +0 -26
  177. package/src/array/takeWhile.spec.ts +0 -34
  178. package/src/array/takeWhile.ts +0 -31
  179. package/src/array/union.spec.ts +0 -10
  180. package/src/array/union.ts +0 -14
  181. package/src/array/unionBy.spec.ts +0 -12
  182. package/src/array/unionBy.ts +0 -35
  183. package/src/array/unionWith.spec.ts +0 -23
  184. package/src/array/unionWith.ts +0 -18
  185. package/src/array/uniq.spec.ts +0 -8
  186. package/src/array/uniq.ts +0 -16
  187. package/src/array/uniqBy.spec.ts +0 -8
  188. package/src/array/uniqBy.ts +0 -17
  189. package/src/array/uniqWith.spec.ts +0 -16
  190. package/src/array/uniqWith.ts +0 -29
  191. package/src/array/xor.spec.ts +0 -13
  192. package/src/array/xor.ts +0 -25
  193. package/src/array/xorBy.spec.ts +0 -16
  194. package/src/array/xorBy.ts +0 -29
  195. package/src/array/xorWith.spec.ts +0 -16
  196. package/src/array/xorWith.ts +0 -28
  197. package/src/array/zip.spec.ts +0 -14
  198. package/src/array/zip.ts +0 -34
  199. package/src/array/zipWith.spec.ts +0 -13
  200. package/src/array/zipWith.ts +0 -23
  201. package/src/function/debounce.spec.ts +0 -76
  202. package/src/function/debounce.ts +0 -42
  203. package/src/function/index.ts +0 -3
  204. package/src/function/once.spec.ts +0 -31
  205. package/src/function/once.ts +0 -34
  206. package/src/function/throttle.spec.ts +0 -32
  207. package/src/function/throttle.ts +0 -39
  208. package/src/index.ts +0 -6
  209. package/src/math/clamp.spec.ts +0 -18
  210. package/src/math/clamp.ts +0 -17
  211. package/src/math/index.ts +0 -3
  212. package/src/math/round.spec.ts +0 -53
  213. package/src/math/round.ts +0 -16
  214. package/src/math/sum.spec.ts +0 -29
  215. package/src/math/sum.ts +0 -17
  216. package/src/object/index.ts +0 -4
  217. package/src/object/omit.spec.ts +0 -10
  218. package/src/object/omit.ts +0 -15
  219. package/src/object/omitBy.ts +0 -3
  220. package/src/object/pick.spec.ts +0 -10
  221. package/src/object/pick.ts +0 -15
  222. package/src/object/pickBy.ts +0 -3
  223. package/src/predicate/index.ts +0 -4
  224. package/src/predicate/isNil.spec.ts +0 -23
  225. package/src/predicate/isNil.ts +0 -8
  226. package/src/predicate/isNotNil.spec.ts +0 -29
  227. package/src/predicate/isNotNil.ts +0 -14
  228. package/src/predicate/isNull.spec.ts +0 -23
  229. package/src/predicate/isNull.ts +0 -8
  230. package/src/predicate/isUndefined.spec.ts +0 -23
  231. package/src/predicate/isUndefined.ts +0 -8
  232. package/src/promise/delay.spec.ts +0 -13
  233. package/src/promise/delay.ts +0 -10
  234. package/src/promise/index.ts +0 -1
  235. package/tsconfig.json +0 -12
  236. package/vitest.config.mts +0 -13
@@ -2,45 +2,225 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _iterableToArrayLimit(r, l) {
6
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
7
- if (null != t) {
8
- var e,
9
- n,
10
- i,
11
- u,
12
- a = [],
13
- f = !0,
14
- o = !1;
15
- try {
16
- if (i = (t = t.call(r)).next, 0 === l) {
17
- if (Object(t) !== t) return;
18
- f = !1;
19
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
20
- } catch (r) {
21
- o = !0, n = r;
22
- } finally {
23
- try {
24
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
25
- } finally {
26
- if (o) throw n;
27
- }
28
- }
29
- return a;
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.');
30
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
+ });
31
102
  }
32
- function _slicedToArray(arr, i) {
33
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
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
+ });
34
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
+
35
218
  function _toConsumableArray(arr) {
36
219
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
37
220
  }
38
221
  function _arrayWithoutHoles(arr) {
39
222
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
40
223
  }
41
- function _arrayWithHoles(arr) {
42
- if (Array.isArray(arr)) return arr;
43
- }
44
224
  function _iterableToArray(iter) {
45
225
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
46
226
  }
@@ -60,9 +240,6 @@ function _arrayLikeToArray(arr, len) {
60
240
  function _nonIterableSpread() {
61
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.");
62
242
  }
63
- function _nonIterableRest() {
64
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
65
- }
66
243
  function _createForOfIteratorHelper(o, allowArrayLike) {
67
244
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
68
245
  if (!it) {
@@ -116,28 +293,47 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
116
293
  }
117
294
 
118
295
  /**
119
- * @name chunk
120
- * Separate an array into smaller arrays of length `size`.
121
- * If the array cannot be separated in equal size, the final sub-array will have the remaining elements.
122
- * @param arr The array to chunk
123
- * @param size The size of smaller arrays
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
+ * // }
124
324
  */
125
- function chunk(arr, size) {
126
- if (!Number.isInteger(size) || size <= 0) {
127
- throw new Error("Size must be an integer greater than zero.");
128
- }
129
- var result = [];
130
- var _iterator = _createForOfIteratorHelper(arr.entries()),
325
+ function groupBy(arr, getKeyFromItem) {
326
+ var result = {};
327
+ var _iterator = _createForOfIteratorHelper(arr),
131
328
  _step;
132
329
  try {
133
330
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
134
- var _step$value = _slicedToArray(_step.value, 2),
135
- index = _step$value[0],
136
- item = _step$value[1];
137
- if (index % size === 0) {
138
- result.push([]);
331
+ var item = _step.value;
332
+ var key = getKeyFromItem(item);
333
+ if (result[key] == null) {
334
+ result[key] = [];
139
335
  }
140
- result[result.length - 1].push(item);
336
+ result[key].push(item);
141
337
  }
142
338
  } catch (err) {
143
339
  _iterator.e(err);
@@ -148,106 +344,21 @@ function chunk(arr, size) {
148
344
  }
149
345
 
150
346
  /**
151
- * @name difference
152
- * Returns the difference of two arrays.
153
- * @param firstArr The array to get the difference from
154
- * @param secondArr The elements to exclude from `firstArr`
155
- */
156
- function difference(firstArr, secondArr) {
157
- return firstArr.filter(function (item) {
158
- return !secondArr.includes(item);
159
- });
160
- }
161
-
162
- /**
163
- * @name differenceBy
164
- * Returns the difference of two arrays. The identity of two elements is calculated after the elements are mapped with `mapper`.
165
- * @param firstArr The array to get the difference from
166
- * @param secondArr The elements to exclude from `firstArr`
167
- * @param mapper The function to map the elements when calculating the difference
168
- */
169
- function differenceBy(firstArr, secondArr, mapper) {
170
- var mappedSecondArr = secondArr.map(function (item) {
171
- return mapper(item);
172
- });
173
- return firstArr.filter(function (item) {
174
- return !mappedSecondArr.includes(mapper(item));
175
- });
176
- }
177
-
178
- /**
179
- * @name differenceWith
180
- * Returns the difference of two arrays. The identity of two elements is calculated with the function `areItemsEqual`.
181
- * @param firstArr The array to get the difference from
182
- * @param secondArr The elements to exclude from `firstArr`
183
- * @param areItemsEqual The function to determine whether two items are equal
184
- */
185
- function differenceWith(firstArr, secondArr, areItemsEqual) {
186
- return firstArr.filter(function (firstItem) {
187
- return secondArr.every(function (secondItem) {
188
- return !areItemsEqual(firstItem, secondItem);
189
- });
190
- });
191
- }
192
-
193
- /**
194
- * @name drop
195
- * Drop some elements from an array from the beginning. This function returns a new array.
196
- * @param arr The element to drop items from the beginning
197
- * @param itemsCount The amount of elements to drop
198
- */
199
- function drop(arr, itemsCount) {
200
- return arr.slice(itemsCount);
201
- }
202
-
203
- /**
204
- * @name dropRight
205
- * Drop some elements from an array from the end. This function returns a new array.
206
- * @param arr The element to drop items from the end
207
- * @param itemsCount The amount of elements to drop
208
- */
209
- function dropRight(arr, itemsCount) {
210
- return arr.slice(0, -itemsCount);
211
- }
212
-
213
- /**
214
- * @name dropWhile
215
- * Drop some elements from an array from the beginning, until `predicate` returns false.
216
- * @param arr The element to drop items from the beginning
217
- * @param canContinueDropping The predicate to check if the function can continue dropping elements.
218
- */
219
- function dropWhile(arr, canContinueDropping) {
220
- var dropEndIndex = arr.findIndex(function (item) {
221
- return !canContinueDropping(item);
222
- });
223
- return arr.slice(dropEndIndex);
224
- }
225
-
226
- /**
227
- * @name dropRightWhile
228
- * Drop some elements from an array from the end, until `predicate` returns false.
229
- * @param arr The element to drop items from the end
230
- * @param canContinueDropping The predicate to check if the function can continue dropping elements.
231
- */
232
- function dropRightWhile(arr, canContinueDropping) {
233
- var reversed = arr.slice().reverse();
234
- var dropped = dropWhile(reversed, canContinueDropping);
235
- return dropped.slice().reverse();
236
- }
237
-
238
- function groupBy() {
239
- throw new Error('Not implemented');
240
- }
241
-
242
- /**
243
- * @name intersection
244
- * @description
245
347
  * Returns the intersection of two arrays.
246
- * @param firstArr The first array to get the intersection
247
- * @param secondArr The second array to get the intersection
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
+ *
248
357
  * @example
249
- * intersection([1, 2], [1, 3]) === [1]
250
- * intersection([1, 2, 3], [2, 3, 4]) === [2, 3]
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.
251
362
  */
252
363
  function intersection(firstArr, secondArr) {
253
364
  return firstArr.filter(function (item) {
@@ -256,15 +367,24 @@ function intersection(firstArr, secondArr) {
256
367
  }
257
368
 
258
369
  /**
259
- * @name intersectionBy
260
- * @description
261
- * Returns the intersection of two arrays. The identity of two elements is calculated after the elements are mapped with `mapper`.
262
- * @param firstArr The first array to get the intersection
263
- * @param secondArr The second array to get the intersection
264
- * @param mapper The function to map the elements when calculating the intersection
265
- * @example
266
- * intersectionBy([1.2, 2.1], [1.4, 3.1], Math.floor) === [1.2]
267
- * intersectionBy([{ foo: 1 }, { foo: 2 }], [{ foo: 1 }, { foo: 3 }], x => x.foo) === [{ foo: 1 }]
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.
268
388
  */
269
389
  function intersectionBy(firstArr, secondArr, mapper) {
270
390
  var mappedSecondArr = secondArr.map(function (x) {
@@ -276,15 +396,25 @@ function intersectionBy(firstArr, secondArr, mapper) {
276
396
  }
277
397
 
278
398
  /**
279
- * @name intersectionWith
280
- * @description
281
- * Returns the intersection of two arrays. The identity of two elements is compared with `areItemsEqual`.
282
- * @param firstArr The first array to get the intersection
283
- * @param secondArr The second array to get the intersection
284
- * @param areItemsEqual The function to compare the identity of two elements
285
- * @example
286
- * intersectionWith([1.2, 2.1], [1.4, 3.1], (x, y) => Math.floor(x) === Math.floor(y)) === [1.2]
287
- * intersectionWith([{ foo: 1 }, { foo: 2 }], [{ foo: 1 }, { foo: 3 }], (x, y) => x.foo === y.foo) === [{ foo: 1 }]
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.
288
418
  */
289
419
  function intersectionWith(firstArr, secondArr, areItemsEqual) {
290
420
  return firstArr.filter(function (firstItem) {
@@ -295,11 +425,25 @@ function intersectionWith(firstArr, secondArr, areItemsEqual) {
295
425
  }
296
426
 
297
427
  /**
298
- * @name partition
299
- * @description
300
- * Creates two arrays: the first array includes items for which isInTruthy returns true, and the second array includes items for which isInTruthy returns false.
301
- * @param arr The array to split into two arrays
302
- * @param isInTruthy The predicate to tell whether an item is included in the first array
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]
303
447
  */
304
448
  function partition(arr, isInTruthy) {
305
449
  var truthy = [];
@@ -324,10 +468,17 @@ function partition(arr, isInTruthy) {
324
468
  }
325
469
 
326
470
  /**
327
- * @name sample
328
- * @description
329
471
  * Returns a random element from an array.
330
- * @param arr The element to get a random element
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.
331
482
  */
332
483
  function sample(arr) {
333
484
  var randomIndex = Math.floor(Math.random() * arr.length);
@@ -335,17 +486,24 @@ function sample(arr) {
335
486
  }
336
487
 
337
488
  /**
338
- * @name shuffle
339
- * @description
340
- * Randomize the order of an array.
341
- * @param arr The array to shuffle
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]
342
500
  */
343
501
  function shuffle(arr) {
344
502
  /**
345
503
  * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
346
504
  */
347
505
  for (var i = arr.length - 1; i >= 1; i--) {
348
- var j = Math.floor(Math.random() * i);
506
+ var j = Math.floor(Math.random() * (i + 1));
349
507
  var _ref = [arr[j], arr[i]];
350
508
  arr[i] = _ref[0];
351
509
  arr[j] = _ref[1];
@@ -382,8 +540,6 @@ function take(arr, count) {
382
540
  /**
383
541
  * Returns a new array containing the last `count` elements from the input array `arr`.
384
542
  * If `count` is greater than the length of `arr`, the entire array is returned.
385
- *
386
- * @template T - Type of elements in the input array.
387
543
  *
388
544
  * @param {T[]} arr - The array to take elements from.
389
545
  * @param {number} count - The number of elements to take.
@@ -473,43 +629,61 @@ function takeWhile(arr, shouldContinueTaking) {
473
629
  }
474
630
 
475
631
  /**
476
- * @name uniq
477
- * @description
478
- * `uniq` removes duplicated elements from the array given as an argument.
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.
479
636
  *
480
- * It filters out elements with the same value, so duplicates of data types like Objects are not checked.
637
+ * @param {T[]} arr - The array to process.
638
+ * @returns {T[]} A new array with only unique values from the original array.
481
639
  *
482
640
  * @example
483
- * ```ts
484
- * uniq([1, 1, 2, 3, 5, 5, 7, 'foo', 'bar', 'bar']);
485
- * // [1, 2, 3, 5, 7, 'foo', 'bar']
486
- * ```
641
+ * * const array = [1, 2, 2, 3, 4, 4, 5];
642
+ * const result = uniq(array);
643
+ * // result will be [1, 2, 3, 4, 5]
487
644
  */
488
645
  function uniq(arr) {
489
- return Array.from(new Set(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;
490
663
  }
491
664
 
492
665
  /**
493
- * `union` function returns the union of the arrays passed as arguments.
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.
494
674
  *
495
675
  * @example
496
- * ```ts
497
- * union([2], [1, 2]);
498
- * // [2, 1]
499
- * ```
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]
500
680
  */
501
- function union() {
502
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
503
- args[_key] = arguments[_key];
504
- }
505
- return uniq(args.flat());
681
+ function union(arr1, arr2) {
682
+ return uniq(arr1.concat(arr2));
506
683
  }
507
684
 
508
685
  /**
509
686
  * Creates an array of unique values, in order, from all given arrays using a provided mapping function to determine equality.
510
- *
511
- * @template T - Type of elements in the input arrays.
512
- * @template U - Type of the values returned by the mapping function.
513
687
  *
514
688
  * @param {T[]} arr1 - The first array.
515
689
  * @param {T[]} arr2 - The second array.
@@ -577,20 +751,26 @@ function uniqWith(arr, areItemsEqual) {
577
751
  }
578
752
 
579
753
  /**
580
- * `unionWith` function returns the union of multiple arrays passed as arguments. During this process, it removes any duplicated elements.
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.
581
764
  *
582
765
  * @example
583
- * ```ts
584
- * unionWith(
585
- * [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }],
586
- * [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }],
587
- * (x, y) => x === y
588
- * );
589
- * // [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
590
- * ```
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
591
771
  */
592
772
  function unionWith(arr1, arr2, areItemsEqual) {
593
- return uniqWith([].concat(_toConsumableArray(arr1), _toConsumableArray(arr2)), areItemsEqual);
773
+ return uniqWith(arr1.concat(arr2), areItemsEqual);
594
774
  }
595
775
 
596
776
  /**
@@ -613,8 +793,6 @@ function uniqBy(arr, converter) {
613
793
  /**
614
794
  * Computes the symmetric difference between two arrays. The symmetric difference is the set of elements
615
795
  * which are in either of the arrays, but not in their intersection.
616
- *
617
- * @template T - Type of elements in the input arrays.
618
796
  *
619
797
  * @param {T[]} arr1 - The first array.
620
798
  * @param {T[]} arr2 - The second array.
@@ -682,13 +860,25 @@ function xorWith(arr1, arr2, areElementsEqual) {
682
860
  }
683
861
 
684
862
  /**
685
- * Merges multiple arrays element-wise. Returns an array where each element is an array containing
686
- * elements from the input arrays at the corresponding index.
863
+ * Combines multiple arrays into a single array of tuples.
687
864
  *
688
- * @param {T[]} arr1 - The first array to be zipped.
689
- * @param {T[]} arr2 - The second array to be zipped.
690
- * @param {T[]} arr3 - The third array to be zipped.
691
- * @param {T[]} arr4 - The fourth array to be zipped.
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]]
692
882
  */
693
883
 
694
884
  function zip() {
@@ -719,9 +909,32 @@ function zip() {
719
909
  }
720
910
 
721
911
  /**
722
- * Combines multiple arrays element-wise using a provided combining function.
723
- * Returns an array where each element is the result of applying the combining function
724
- * to the corresponding elements from the input arrays.
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`]
725
938
  */
726
939
 
727
940
  function zipWith(arr1) {