Function minOf

  • Applies the given selector to all elements of the given collection and returns the min value of all elements. If an empty array is provided the function will return undefined.

    Type Parameters

    • T

      The type of the elements in the array.

    Parameters

    • array: Iterable<T, any, any>

      The array to find the minimum element in.

    • selector: ((el: T) => number)

      The function to get the value to compare from each element.

        • (el): number
        • Parameters

          • el: T

          Returns number

    Returns number | undefined

    The smallest value of the given function or undefined if there are no elements.

    import { minOf } from "@std/collections/min-of";
    import { assertEquals } from "@std/assert";

    const inventory = [
    { name: "mustard", count: 2 },
    { name: "soy", count: 4 },
    { name: "tomato", count: 32 },
    ];

    const minCount = minOf(inventory, (item) => item.count);

    assertEquals(minCount, 2);
  • Applies the given selector to all elements of the given collection and returns the min value of all elements. If an empty array is provided the function will return undefined.

    Type Parameters

    • T

      The type of the elements in the array.

    Parameters

    • array: Iterable<T, any, any>

      The array to find the minimum element in.

    • selector: ((el: T) => bigint)

      The function to get the value to compare from each element.

        • (el): bigint
        • Parameters

          • el: T

          Returns bigint

    Returns bigint | undefined

    The first element that is the smallest value of the given function or undefined if there are no elements.

    import { minOf } from "@std/collections/min-of";
    import { assertEquals } from "@std/assert";

    const inventory = [
    { name: "mustard", count: 2n },
    { name: "soy", count: 4n },
    { name: "tomato", count: 32n },
    ];

    const minCount = minOf(inventory, (item) => item.count);

    assertEquals(minCount, 2n);