Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/collections/mod.ts>minWith

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function minWith
import { minWith } from "https://deno.land/std@0.139.0/collections/mod.ts";

Returns the first element having the smallest value according to the provided comparator or undefined if there are no elements

Example:

import { minWith } from "https://deno.land/std@0.139.0/collections/mod.ts";
import { assertEquals } from "https://deno.land/std@0.139.0/testing/asserts.ts";

const people = ["Kim", "Anna", "John"];
const smallestName = minWith(people, (a, b) => a.length - b.length);

assertEquals(smallestName, "Kim");

Parameters

array: readonly T[]
comparator: (a: T, b: T) => number

Returns

T | undefined