@zelgadis87/utils-core 5.3.7 → 5.3.8

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.
package/.rollup/index.cjs CHANGED
@@ -461,22 +461,82 @@ function sum(arr) {
461
461
  function sumBy(arr, getter) {
462
462
  return sum(arr.map(getter));
463
463
  }
464
+ /**
465
+ * Finds the minimum value in an array of numbers.
466
+ * @param arr - The array of numbers to search
467
+ * @returns The minimum value, or null if the array is empty
468
+ */
464
469
  function min(arr) {
465
470
  if (arr.length === 0)
466
471
  return null;
467
472
  return arr.reduce((min, cur) => cur < min ? cur : min);
468
473
  }
474
+ /**
475
+ * Finds the minimum numeric value extracted from array elements using a getter function.
476
+ * @param arr - The array of elements to search
477
+ * @param getter - Function to extract a numeric value from each element
478
+ * @returns The minimum extracted value, or null if the array is empty
479
+ */
469
480
  function minBy(arr, getter) {
470
481
  return min(arr.map(getter));
471
482
  }
483
+ /**
484
+ * Finds the maximum value in an array of numbers.
485
+ * @param arr - The array of numbers to search
486
+ * @returns The maximum value, or null if the array is empty
487
+ */
472
488
  function max(arr) {
473
489
  if (arr.length === 0)
474
490
  return null;
475
491
  return arr.reduce((max, cur) => cur > max ? cur : max);
476
492
  }
493
+ /**
494
+ * Finds the maximum numeric value extracted from array elements using a getter function.
495
+ * @param arr - The array of elements to search
496
+ * @param getter - Function to extract a numeric value from each element
497
+ * @returns The maximum extracted value, or null if the array is empty
498
+ */
477
499
  function maxBy(arr, getter) {
478
500
  return max(arr.map(getter));
479
501
  }
502
+ /**
503
+ * Finds the element with the maximum numeric value extracted using a getter function.
504
+ * @param arr - The array of elements to search
505
+ * @param getter - Function to extract a numeric value from each element
506
+ * @returns The element with the maximum value, or null if the array is empty
507
+ */
508
+ function havingMaxBy(arr, getter) {
509
+ if (arr.length === 0)
510
+ return null;
511
+ return arr.reduce((ret, cur) => {
512
+ const curValue = getter(cur);
513
+ if (curValue > ret.max) {
514
+ return { value: cur, max: curValue };
515
+ }
516
+ else {
517
+ return ret;
518
+ }
519
+ }, { value: null, max: -Infinity }).value;
520
+ }
521
+ /**
522
+ * Finds the element with the minimum numeric value extracted using a getter function.
523
+ * @param arr - The array of elements to search
524
+ * @param getter - Function to extract a numeric value from each element
525
+ * @returns The element with the minimum value, or null if the array is empty
526
+ */
527
+ function havingMinBy(arr, getter) {
528
+ if (arr.length === 0)
529
+ return null;
530
+ return arr.reduce((ret, cur) => {
531
+ const curValue = getter(cur);
532
+ if (curValue < ret.min) {
533
+ return { value: cur, min: curValue };
534
+ }
535
+ else {
536
+ return ret;
537
+ }
538
+ }, { value: null, min: +Infinity }).value;
539
+ }
480
540
 
481
541
  function constant(v) { return () => v; }
482
542
  function identity(t) { return t; }
@@ -3664,6 +3724,8 @@ exports.groupByStringWith = groupByStringWith;
3664
3724
  exports.groupBySymbol = groupBySymbol;
3665
3725
  exports.groupBySymbolWith = groupBySymbolWith;
3666
3726
  exports.hashCode = hashCode;
3727
+ exports.havingMaxBy = havingMaxBy;
3728
+ exports.havingMinBy = havingMinBy;
3667
3729
  exports.head = head;
3668
3730
  exports.identity = identity;
3669
3731
  exports.ifDefined = ifDefined;