Returns the first element having the smallest value according to the provided comparator or undefined if there are no elements.
The type of the elements in the array.
The array to find the minimum element in.
The function to compare elements.
The first element that is the smallest value of the given function or undefined if there are no elements.
import { minWith } from "@std/collections/min-with";import { assertEquals } from "@std/assert";const people = ["Kim", "Anna", "John"];const smallestName = minWith(people, (a, b) => a.length - b.length);assertEquals(smallestName, "Kim"); Copy
import { minWith } from "@std/collections/min-with";import { assertEquals } from "@std/assert";const people = ["Kim", "Anna", "John"];const smallestName = minWith(people, (a, b) => a.length - b.length);assertEquals(smallestName, "Kim");
Returns the first element having the smallest value according to the provided comparator or undefined if there are no elements.