es-toolkit 1.20.0 → 1.21.0-dev.660

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 (126) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/_chunk/{isWeakSet-E_VMwB.js → isWeakSet-1xFSnK.js} +5 -0
  3. package/dist/_chunk/{toMerged-Bzkqyz.js → toMerged-D-sLFv.js} +10 -8
  4. package/dist/_chunk/{zipWith-CDtN9Y.js → zipWith-DEcUS4.js} +25 -12
  5. package/dist/array/compact.d.mts +4 -4
  6. package/dist/array/compact.d.ts +4 -4
  7. package/dist/array/compact.mjs +2 -1
  8. package/dist/array/countBy.mjs +2 -1
  9. package/dist/array/flatten.mjs +2 -1
  10. package/dist/array/groupBy.mjs +2 -1
  11. package/dist/array/index.js +1 -1
  12. package/dist/array/keyBy.mjs +2 -1
  13. package/dist/array/maxBy.d.mts +16 -0
  14. package/dist/array/maxBy.d.ts +16 -0
  15. package/dist/array/maxBy.mjs +2 -1
  16. package/dist/array/minBy.d.mts +16 -0
  17. package/dist/array/minBy.d.ts +16 -0
  18. package/dist/array/minBy.mjs +2 -1
  19. package/dist/array/partition.mjs +2 -1
  20. package/dist/array/takeWhile.mjs +2 -1
  21. package/dist/array/unionBy.mjs +3 -1
  22. package/dist/array/uniqBy.mjs +2 -1
  23. package/dist/array/uniqWith.mjs +2 -1
  24. package/dist/browser.global.js +1 -1
  25. package/dist/browser.global.js.map +1 -1
  26. package/dist/compat/array/castArray.d.mts +2 -2
  27. package/dist/compat/array/castArray.d.ts +2 -2
  28. package/dist/compat/array/flatten.mjs +2 -1
  29. package/dist/compat/function/curry.mjs +26 -34
  30. package/dist/compat/function/defer.d.mts +16 -0
  31. package/dist/compat/function/defer.d.ts +16 -0
  32. package/dist/compat/function/defer.mjs +8 -0
  33. package/dist/compat/index.d.mts +13 -5
  34. package/dist/compat/index.d.ts +13 -5
  35. package/dist/compat/index.js +200 -71
  36. package/dist/compat/index.mjs +14 -6
  37. package/dist/compat/math/inRange.d.mts +27 -0
  38. package/dist/compat/math/inRange.d.ts +27 -0
  39. package/dist/compat/math/inRange.mjs +28 -0
  40. package/dist/compat/math/max.mjs +2 -1
  41. package/dist/compat/math/min.mjs +2 -1
  42. package/dist/compat/math/random.d.mts +50 -0
  43. package/dist/compat/math/random.d.ts +50 -0
  44. package/dist/compat/math/random.mjs +70 -0
  45. package/dist/compat/object/cloneDeep.d.mts +49 -0
  46. package/dist/compat/object/cloneDeep.d.ts +49 -0
  47. package/dist/compat/object/pick.mjs +2 -1
  48. package/dist/compat/predicate/conformsTo.mjs +3 -1
  49. package/dist/compat/predicate/isArrayLikeObject.d.mts +15 -0
  50. package/dist/compat/predicate/isArrayLikeObject.d.ts +15 -0
  51. package/dist/compat/predicate/isArrayLikeObject.mjs +8 -0
  52. package/dist/compat/predicate/isBoolean.d.mts +3 -3
  53. package/dist/compat/predicate/isBoolean.d.ts +3 -3
  54. package/dist/compat/predicate/isBoolean.mjs +2 -10
  55. package/dist/compat/predicate/isError.d.mts +16 -0
  56. package/dist/compat/predicate/isError.d.ts +16 -0
  57. package/dist/compat/predicate/isError.mjs +7 -0
  58. package/dist/compat/predicate/isFinite.d.mts +20 -0
  59. package/dist/compat/predicate/isFinite.d.ts +20 -0
  60. package/dist/compat/predicate/isFinite.mjs +5 -0
  61. package/dist/compat/predicate/isNil.d.mts +22 -0
  62. package/dist/compat/predicate/isNil.d.ts +22 -0
  63. package/dist/compat/predicate/isNumber.mjs +1 -6
  64. package/dist/compat/predicate/isRegExp.mjs +2 -2
  65. package/dist/compat/predicate/isString.d.mts +1 -1
  66. package/dist/compat/predicate/isString.d.ts +1 -1
  67. package/dist/compat/predicate/isString.mjs +1 -9
  68. package/dist/compat/predicate/isSymbol.mjs +1 -1
  69. package/dist/compat/string/pad.d.mts +19 -0
  70. package/dist/compat/string/pad.d.ts +19 -0
  71. package/dist/compat/string/pad.mjs +8 -0
  72. package/dist/compat/string/padEnd.mjs +3 -1
  73. package/dist/compat/string/padStart.mjs +3 -1
  74. package/dist/compat/util/toFinite.d.mts +17 -0
  75. package/dist/compat/util/toFinite.d.ts +17 -0
  76. package/dist/compat/util/toFinite.mjs +15 -0
  77. package/dist/compat/util/toInteger.d.mts +17 -0
  78. package/dist/compat/util/toInteger.d.ts +17 -0
  79. package/dist/compat/util/toInteger.mjs +9 -0
  80. package/dist/compat/util/toNumber.d.mts +19 -0
  81. package/dist/compat/util/toNumber.d.ts +19 -0
  82. package/dist/compat/util/toNumber.mjs +10 -0
  83. package/dist/function/curry.d.mts +18 -19
  84. package/dist/function/curry.d.ts +18 -19
  85. package/dist/index.d.mts +2 -0
  86. package/dist/index.d.ts +2 -0
  87. package/dist/index.js +10 -8
  88. package/dist/index.mjs +2 -0
  89. package/dist/math/random.d.mts +1 -1
  90. package/dist/math/random.d.ts +1 -1
  91. package/dist/math/range.d.mts +7 -25
  92. package/dist/math/range.d.ts +7 -25
  93. package/dist/object/index.js +8 -4
  94. package/dist/object/omit.d.mts +1 -1
  95. package/dist/object/omit.d.ts +1 -1
  96. package/dist/object/omit.mjs +2 -1
  97. package/dist/object/omitBy.mjs +5 -4
  98. package/dist/object/pick.mjs +5 -2
  99. package/dist/object/pickBy.mjs +5 -4
  100. package/dist/predicate/index.d.mts +1 -0
  101. package/dist/predicate/index.d.ts +1 -0
  102. package/dist/predicate/index.js +5 -4
  103. package/dist/predicate/index.mjs +1 -0
  104. package/dist/predicate/isError.d.mts +16 -0
  105. package/dist/predicate/isError.d.ts +16 -0
  106. package/dist/predicate/isError.mjs +5 -0
  107. package/dist/promise/withTimeout.d.mts +8 -2
  108. package/dist/promise/withTimeout.d.ts +8 -2
  109. package/dist/string/_internal/getWords.mjs +1 -1
  110. package/dist/string/camelCase.d.mts +1 -0
  111. package/dist/string/camelCase.d.ts +1 -0
  112. package/dist/string/constantCase.d.mts +17 -0
  113. package/dist/string/constantCase.d.ts +17 -0
  114. package/dist/string/constantCase.mjs +8 -0
  115. package/dist/string/index.d.mts +1 -0
  116. package/dist/string/index.d.ts +1 -0
  117. package/dist/string/index.js +10 -8
  118. package/dist/string/index.mjs +1 -0
  119. package/dist/string/startCase.d.mts +1 -1
  120. package/dist/string/startCase.d.ts +1 -1
  121. package/dist/string/startCase.mjs +3 -7
  122. package/dist/string/trimStart.d.mts +1 -1
  123. package/dist/string/trimStart.d.ts +1 -1
  124. package/dist/string/upperFirst.d.mts +3 -3
  125. package/dist/string/upperFirst.d.ts +3 -3
  126. package/package.json +2 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # es-toolkit Changelog
2
2
 
3
+ ## Version v1.21.0
4
+
5
+ Released on September 25th, 2024.
6
+
7
+ - Added support for [constantCase](https://es-toolkit.slash.page/reference/string/constantCase.html) and [isError](https://es-toolkit.slash.page/reference/predicate/isError.html).
8
+ - Added compatibility functions for [pad](https://es-toolkit.slash.page/reference/compat/string/pad.html), [padStart](https://es-toolkit.slash.page/reference/compat/string/padStart.html), [padEnd](https://es-toolkit.slash.page/reference/compat/string/padEnd.html), [defer](https://es-toolkit.slash.page/reference/compat/function/defer.html), [isFinite](https://es-toolkit.slash.page/reference/compat/predicate/isFinite.html), [toNumber](https://es-toolkit.slash.page/reference/compat/math/toNumber.html), [toFinite](https://es-toolkit.slash.page/reference/compat/math/toFinite.html), and [toInteger](https://es-toolkit.slash.page/reference/compat/math/toInteger.html).
9
+ - Improved performance for [flatten](https://es-toolkit.slash.page/reference/array/flatten.html), [isNumber](https://es-toolkit.slash.page/reference/predicate/isNumber.html), [isString](https://es-toolkit.slash.page/reference/predicate/isString.html), [isSymbol](https://es-toolkit.slash.page/reference/predicate/isSymbol.html), [isRegExp](https://es-toolkit.slash.page/reference/predicate/isRegExp.html), and [isBoolean](https://es-toolkit.slash.page/reference/predicate/isBoolean.html).
10
+ - Fixed [compact](https://es-toolkit.slash.page/reference/array/compact.html) to correctly exclude `0n` as a falsey value.
11
+ - Fixed [pick](https://es-toolkit.slash.page/reference/object/pick.html) to not pick nonexistent keys from the original object.
12
+ - Fixed [omit](https://es-toolkit.slash.page/reference/object/omit.html) to accept readonly arrays.
13
+
14
+ This version includes contributions from @hyesungoh, @D-Sketon, @mass2527, @gweesin, @VVSOGI, @coding-honey, @seonghun0828, and @jsparkdev. Thank you for your valuable contributions!
15
+
3
16
  ## Version v1.20.0
4
17
 
5
18
  Released on September 20th, 2024.
@@ -238,6 +238,10 @@ function isFunction(value) {
238
238
  return typeof value === 'function';
239
239
  }
240
240
 
241
+ function isRegExp(value) {
242
+ return value instanceof RegExp;
243
+ }
244
+
241
245
  function isWeakMap(value) {
242
246
  return value instanceof WeakMap;
243
247
  }
@@ -257,6 +261,7 @@ exports.isLength = isLength;
257
261
  exports.isNil = isNil;
258
262
  exports.isNotNil = isNotNil;
259
263
  exports.isNull = isNull;
264
+ exports.isRegExp = isRegExp;
260
265
  exports.isUndefined = isUndefined;
261
266
  exports.isWeakMap = isWeakMap;
262
267
  exports.isWeakSet = isWeakSet;
@@ -4,22 +4,24 @@ const isPlainObject = require('./isPlainObject-BIekvL.js');
4
4
 
5
5
  function omitBy(obj, shouldOmit) {
6
6
  const result = {};
7
- for (const [key, value] of Object.entries(obj)) {
8
- if (shouldOmit(value, key)) {
9
- continue;
7
+ const objEntries = Object.entries(obj);
8
+ for (let i = 0; i < objEntries.length; i++) {
9
+ const [key, value] = objEntries[i];
10
+ if (!shouldOmit(value, key)) {
11
+ result[key] = value;
10
12
  }
11
- result[key] = value;
12
13
  }
13
14
  return result;
14
15
  }
15
16
 
16
17
  function pickBy(obj, shouldPick) {
17
18
  const result = {};
18
- for (const [key, value] of Object.entries(obj)) {
19
- if (!shouldPick(value, key)) {
20
- continue;
19
+ const objEntries = Object.entries(obj);
20
+ for (let i = 0; i < objEntries.length; i++) {
21
+ const [key, value] = objEntries[i];
22
+ if (shouldPick(value, key)) {
23
+ result[key] = value;
21
24
  }
22
- result[key] = value;
23
25
  }
24
26
  return result;
25
27
  }
@@ -27,7 +27,8 @@ function chunk(arr, size) {
27
27
 
28
28
  function compact(arr) {
29
29
  const result = [];
30
- for (const item of arr) {
30
+ for (let i = 0; i < arr.length; i++) {
31
+ const item = arr[i];
31
32
  if (item) {
32
33
  result.push(item);
33
34
  }
@@ -37,7 +38,8 @@ function compact(arr) {
37
38
 
38
39
  function countBy(arr, mapper) {
39
40
  const result = {};
40
- for (const item of arr) {
41
+ for (let i = 0; i < arr.length; i++) {
42
+ const item = arr[i];
41
43
  const key = mapper(item);
42
44
  result[key] = (result[key] ?? 0) + 1;
43
45
  }
@@ -103,7 +105,8 @@ function flatten(arr, depth = 1) {
103
105
  const result = [];
104
106
  const flooredDepth = Math.floor(depth);
105
107
  const recursive = (arr, currentDepth) => {
106
- for (const item of arr) {
108
+ for (let i = 0; i < arr.length; i++) {
109
+ const item = arr[i];
107
110
  if (Array.isArray(item) && currentDepth < flooredDepth) {
108
111
  recursive(item, currentDepth + 1);
109
112
  }
@@ -137,7 +140,8 @@ function forEachRight(arr, callback) {
137
140
 
138
141
  function groupBy(arr, getKeyFromItem) {
139
142
  const result = Object.create(null);
140
- for (const item of arr) {
143
+ for (let i = 0; i < arr.length; i++) {
144
+ const item = arr[i];
141
145
  const key = getKeyFromItem(item);
142
146
  if (result[key] == null) {
143
147
  result[key] = [];
@@ -181,7 +185,8 @@ function isSubset(superset, subset) {
181
185
 
182
186
  function keyBy(arr, getKeyFromItem) {
183
187
  const result = {};
184
- for (const item of arr) {
188
+ for (let i = 0; i < arr.length; i++) {
189
+ const item = arr[i];
185
190
  const key = getKeyFromItem(item);
186
191
  result[key] = item;
187
192
  }
@@ -195,7 +200,8 @@ function last(arr) {
195
200
  function maxBy(items, getValue) {
196
201
  let maxElement = items[0];
197
202
  let max = -Infinity;
198
- for (const element of items) {
203
+ for (let i = 0; i < items.length; i++) {
204
+ const element = items[i];
199
205
  const value = getValue(element);
200
206
  if (value > max) {
201
207
  max = value;
@@ -208,7 +214,8 @@ function maxBy(items, getValue) {
208
214
  function minBy(items, getValue) {
209
215
  let minElement = items[0];
210
216
  let min = Infinity;
211
- for (const element of items) {
217
+ for (let i = 0; i < items.length; i++) {
218
+ const element = items[i];
212
219
  const value = getValue(element);
213
220
  if (value < min) {
214
221
  min = value;
@@ -221,7 +228,8 @@ function minBy(items, getValue) {
221
228
  function partition(arr, isInTruthy) {
222
229
  const truthy = [];
223
230
  const falsy = [];
224
- for (const item of arr) {
231
+ for (let i = 0; i < arr.length; i++) {
232
+ const item = arr[i];
225
233
  if (isInTruthy(item)) {
226
234
  truthy.push(item);
227
235
  }
@@ -298,7 +306,8 @@ function takeRightWhile(arr, shouldContinueTaking) {
298
306
 
299
307
  function takeWhile(arr, shouldContinueTaking) {
300
308
  const result = [];
301
- for (const item of arr) {
309
+ for (let i = 0; i < arr.length; i++) {
310
+ const item = arr[i];
302
311
  if (!shouldContinueTaking(item)) {
303
312
  break;
304
313
  }
@@ -328,7 +337,9 @@ function union(arr1, arr2) {
328
337
 
329
338
  function unionBy(arr1, arr2, mapper) {
330
339
  const map = new Map();
331
- for (const item of [...arr1, ...arr2]) {
340
+ const items = [...arr1, ...arr2];
341
+ for (let i = 0; i < items.length; i++) {
342
+ const item = items[i];
332
343
  const key = mapper(item);
333
344
  if (!map.has(key)) {
334
345
  map.set(key, item);
@@ -339,7 +350,8 @@ function unionBy(arr1, arr2, mapper) {
339
350
 
340
351
  function uniqWith(arr, areItemsEqual) {
341
352
  const result = [];
342
- for (const item of arr) {
353
+ for (let i = 0; i < arr.length; i++) {
354
+ const item = arr[i];
343
355
  const isUniq = result.every(v => !areItemsEqual(v, item));
344
356
  if (isUniq) {
345
357
  result.push(item);
@@ -354,7 +366,8 @@ function unionWith(arr1, arr2, areItemsEqual) {
354
366
 
355
367
  function uniqBy(arr, mapper) {
356
368
  const map = new Map();
357
- for (const item of arr) {
369
+ for (let i = 0; i < arr.length; i++) {
370
+ const item = arr[i];
358
371
  const key = mapper(item);
359
372
  if (!map.has(key)) {
360
373
  map.set(key, item);
@@ -1,13 +1,13 @@
1
- type NotFalsey<T> = Exclude<T, false | null | 0 | '' | undefined>;
1
+ type NotFalsey<T> = Exclude<T, false | null | 0 | 0n | '' | undefined>;
2
2
  /**
3
- * Removes falsey values (false, null, 0, '', undefined, NaN) from an array.
3
+ * Removes falsey values (false, null, 0, 0n, '', undefined, NaN) from an array.
4
4
  *
5
5
  * @template T - The type of elements in the array.
6
6
  * @param {T[]} arr - The input array to remove falsey values.
7
- * @returns {Array<Exclude<T, false | null | 0 | '' | undefined>>} - A new array with all falsey values removed.
7
+ * @returns {Array<Exclude<T, false | null | 0 | 0n | '' | undefined>>} - A new array with all falsey values removed.
8
8
  *
9
9
  * @example
10
- * compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
10
+ * compact([0, 0n, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
11
11
  * Returns: [1, 2, 3, 4, 5]
12
12
  */
13
13
  declare function compact<T>(arr: readonly T[]): Array<NotFalsey<T>>;
@@ -1,13 +1,13 @@
1
- type NotFalsey<T> = Exclude<T, false | null | 0 | '' | undefined>;
1
+ type NotFalsey<T> = Exclude<T, false | null | 0 | 0n | '' | undefined>;
2
2
  /**
3
- * Removes falsey values (false, null, 0, '', undefined, NaN) from an array.
3
+ * Removes falsey values (false, null, 0, 0n, '', undefined, NaN) from an array.
4
4
  *
5
5
  * @template T - The type of elements in the array.
6
6
  * @param {T[]} arr - The input array to remove falsey values.
7
- * @returns {Array<Exclude<T, false | null | 0 | '' | undefined>>} - A new array with all falsey values removed.
7
+ * @returns {Array<Exclude<T, false | null | 0 | 0n | '' | undefined>>} - A new array with all falsey values removed.
8
8
  *
9
9
  * @example
10
- * compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
10
+ * compact([0, 0n, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
11
11
  * Returns: [1, 2, 3, 4, 5]
12
12
  */
13
13
  declare function compact<T>(arr: readonly T[]): Array<NotFalsey<T>>;
@@ -1,6 +1,7 @@
1
1
  function compact(arr) {
2
2
  const result = [];
3
- for (const item of arr) {
3
+ for (let i = 0; i < arr.length; i++) {
4
+ const item = arr[i];
4
5
  if (item) {
5
6
  result.push(item);
6
7
  }
@@ -1,6 +1,7 @@
1
1
  function countBy(arr, mapper) {
2
2
  const result = {};
3
- for (const item of arr) {
3
+ for (let i = 0; i < arr.length; i++) {
4
+ const item = arr[i];
4
5
  const key = mapper(item);
5
6
  result[key] = (result[key] ?? 0) + 1;
6
7
  }
@@ -2,7 +2,8 @@ function flatten(arr, depth = 1) {
2
2
  const result = [];
3
3
  const flooredDepth = Math.floor(depth);
4
4
  const recursive = (arr, currentDepth) => {
5
- for (const item of arr) {
5
+ for (let i = 0; i < arr.length; i++) {
6
+ const item = arr[i];
6
7
  if (Array.isArray(item) && currentDepth < flooredDepth) {
7
8
  recursive(item, currentDepth + 1);
8
9
  }
@@ -1,6 +1,7 @@
1
1
  function groupBy(arr, getKeyFromItem) {
2
2
  const result = Object.create(null);
3
- for (const item of arr) {
3
+ for (let i = 0; i < arr.length; i++) {
4
+ const item = arr[i];
4
5
  const key = getKeyFromItem(item);
5
6
  if (result[key] == null) {
6
7
  result[key] = [];
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zipWith = require('../_chunk/zipWith-CDtN9Y.js');
5
+ const zipWith = require('../_chunk/zipWith-DEcUS4.js');
6
6
 
7
7
  function drop(arr, itemsCount) {
8
8
  itemsCount = Math.max(itemsCount, 0);
@@ -1,6 +1,7 @@
1
1
  function keyBy(arr, getKeyFromItem) {
2
2
  const result = {};
3
- for (const item of arr) {
3
+ for (let i = 0; i < arr.length; i++) {
4
+ const item = arr[i];
4
5
  const key = getKeyFromItem(item);
5
6
  result[key] = item;
6
7
  }
@@ -9,6 +9,14 @@
9
9
  * @example
10
10
  * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
11
11
  * maxBy([], x => x.a); // Returns: undefined
12
+ * maxBy(
13
+ * [
14
+ * { name: 'john', age: 30 },
15
+ * { name: 'jane', age: 28 },
16
+ * { name: 'joe', age: 26 },
17
+ * ],
18
+ * x => x.age
19
+ * ); // Returns: { name: 'john', age: 30 }
12
20
  */
13
21
  declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
14
22
  /**
@@ -22,6 +30,14 @@ declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
22
30
  * @example
23
31
  * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
24
32
  * maxBy([], x => x.a); // Returns: undefined
33
+ * maxBy(
34
+ * [
35
+ * { name: 'john', age: 30 },
36
+ * { name: 'jane', age: 28 },
37
+ * { name: 'joe', age: 26 },
38
+ * ],
39
+ * x => x.age
40
+ * ); // Returns: { name: 'john', age: 30 }
25
41
  */
26
42
  declare function maxBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
27
43
 
@@ -9,6 +9,14 @@
9
9
  * @example
10
10
  * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
11
11
  * maxBy([], x => x.a); // Returns: undefined
12
+ * maxBy(
13
+ * [
14
+ * { name: 'john', age: 30 },
15
+ * { name: 'jane', age: 28 },
16
+ * { name: 'joe', age: 26 },
17
+ * ],
18
+ * x => x.age
19
+ * ); // Returns: { name: 'john', age: 30 }
12
20
  */
13
21
  declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
14
22
  /**
@@ -22,6 +30,14 @@ declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
22
30
  * @example
23
31
  * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
24
32
  * maxBy([], x => x.a); // Returns: undefined
33
+ * maxBy(
34
+ * [
35
+ * { name: 'john', age: 30 },
36
+ * { name: 'jane', age: 28 },
37
+ * { name: 'joe', age: 26 },
38
+ * ],
39
+ * x => x.age
40
+ * ); // Returns: { name: 'john', age: 30 }
25
41
  */
26
42
  declare function maxBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
27
43
 
@@ -1,7 +1,8 @@
1
1
  function maxBy(items, getValue) {
2
2
  let maxElement = items[0];
3
3
  let max = -Infinity;
4
- for (const element of items) {
4
+ for (let i = 0; i < items.length; i++) {
5
+ const element = items[i];
5
6
  const value = getValue(element);
6
7
  if (value > max) {
7
8
  max = value;
@@ -9,6 +9,14 @@
9
9
  * @example
10
10
  * minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
11
11
  * minBy([], x => x.a); // Returns: undefined
12
+ * minBy(
13
+ * [
14
+ * { name: 'john', age: 30 },
15
+ * { name: 'jane', age: 28 },
16
+ * { name: 'joe', age: 26 },
17
+ * ],
18
+ * x => x.age
19
+ * ); // Returns: { name: 'joe', age: 26 }
12
20
  */
13
21
  declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
14
22
  /**
@@ -22,6 +30,14 @@ declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
22
30
  * @example
23
31
  * minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
24
32
  * minBy([], x => x.a); // Returns: undefined
33
+ * minBy(
34
+ * [
35
+ * { name: 'john', age: 30 },
36
+ * { name: 'jane', age: 28 },
37
+ * { name: 'joe', age: 26 },
38
+ * ],
39
+ * x => x.age
40
+ * ); // Returns: { name: 'joe', age: 26 }
25
41
  */
26
42
  declare function minBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
27
43
 
@@ -9,6 +9,14 @@
9
9
  * @example
10
10
  * minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
11
11
  * minBy([], x => x.a); // Returns: undefined
12
+ * minBy(
13
+ * [
14
+ * { name: 'john', age: 30 },
15
+ * { name: 'jane', age: 28 },
16
+ * { name: 'joe', age: 26 },
17
+ * ],
18
+ * x => x.age
19
+ * ); // Returns: { name: 'joe', age: 26 }
12
20
  */
13
21
  declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
14
22
  /**
@@ -22,6 +30,14 @@ declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) =>
22
30
  * @example
23
31
  * minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
24
32
  * minBy([], x => x.a); // Returns: undefined
33
+ * minBy(
34
+ * [
35
+ * { name: 'john', age: 30 },
36
+ * { name: 'jane', age: 28 },
37
+ * { name: 'joe', age: 26 },
38
+ * ],
39
+ * x => x.age
40
+ * ); // Returns: { name: 'joe', age: 26 }
25
41
  */
26
42
  declare function minBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
27
43
 
@@ -1,7 +1,8 @@
1
1
  function minBy(items, getValue) {
2
2
  let minElement = items[0];
3
3
  let min = Infinity;
4
- for (const element of items) {
4
+ for (let i = 0; i < items.length; i++) {
5
+ const element = items[i];
5
6
  const value = getValue(element);
6
7
  if (value < min) {
7
8
  min = value;
@@ -1,7 +1,8 @@
1
1
  function partition(arr, isInTruthy) {
2
2
  const truthy = [];
3
3
  const falsy = [];
4
- for (const item of arr) {
4
+ for (let i = 0; i < arr.length; i++) {
5
+ const item = arr[i];
5
6
  if (isInTruthy(item)) {
6
7
  truthy.push(item);
7
8
  }
@@ -1,6 +1,7 @@
1
1
  function takeWhile(arr, shouldContinueTaking) {
2
2
  const result = [];
3
- for (const item of arr) {
3
+ for (let i = 0; i < arr.length; i++) {
4
+ const item = arr[i];
4
5
  if (!shouldContinueTaking(item)) {
5
6
  break;
6
7
  }
@@ -1,6 +1,8 @@
1
1
  function unionBy(arr1, arr2, mapper) {
2
2
  const map = new Map();
3
- for (const item of [...arr1, ...arr2]) {
3
+ const items = [...arr1, ...arr2];
4
+ for (let i = 0; i < items.length; i++) {
5
+ const item = items[i];
4
6
  const key = mapper(item);
5
7
  if (!map.has(key)) {
6
8
  map.set(key, item);
@@ -1,6 +1,7 @@
1
1
  function uniqBy(arr, mapper) {
2
2
  const map = new Map();
3
- for (const item of arr) {
3
+ for (let i = 0; i < arr.length; i++) {
4
+ const item = arr[i];
4
5
  const key = mapper(item);
5
6
  if (!map.has(key)) {
6
7
  map.set(key, item);
@@ -1,6 +1,7 @@
1
1
  function uniqWith(arr, areItemsEqual) {
2
2
  const result = [];
3
- for (const item of arr) {
3
+ for (let i = 0; i < arr.length; i++) {
4
+ const item = arr[i];
4
5
  const isUniq = result.every(v => !areItemsEqual(v, item));
5
6
  if (isUniq) {
6
7
  result.push(item);