Function minOf
- min
Of <T>(array, selector): number | undefined Type Parameters
Parameters
Returns number | undefined
The smallest value of the given function or undefined if there are no elements.
Example: Basic usage
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);- min
Of <T>(array, selector): bigint | undefined 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
Parameters
Returns bigint | undefined
The first element that is the smallest value of the given function or undefined if there are no elements.
Example: Basic usage
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);
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.