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

x/fathym_common/src/src.deps.ts>minWith

The Fathym Reference Architecture provides the common foundation for applications built in Typescript.
Go to Latest
function minWith
import { minWith } from "https://deno.land/x/fathym_common@v0.0.142/src/src.deps.ts";

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

Examples

Example 1

import { minWith } from "https://deno.land/std@0.224.0/collections/min_with.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/assert_equals.ts";

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

assertEquals(smallestName, "Kim");

Parameters

array: Iterable<T>
comparator: (a: T, b: T) => number

Returns

T | undefined