std/collections/mod.ts

Deno standard library
Go to Latest
function minOf
import { minOf } from "https://deno.land/std@0.147.0/collections/mod.ts?s=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

Example:

import { minOf } from "https://deno.land/std@0.147.0/collections/min_of.ts"
import { assertEquals } from "https://deno.land/std@0.147.0/testing/asserts.ts"

const inventory = [
     { name: "mustard", count: 2 },
     { name: "soy", count: 4 },
     { name: "tomato", count: 32 },
];
const minCount = minOf(inventory, (i) => i.count);

assertEquals(minCount, 2);

Parameters

array: readonly T[][src]
selector: (el: T) => number[src]

Returns

number | undefined[src]

Parameters

array: readonly T[][src]
selector: (el: T) => bigint[src]

Returns

bigint | undefined[src]

Type Parameters

S extends ((el: T) => number) | ((el: T) => bigint)[src]

Parameters

array: readonly T[][src]
selector: S[src]

Returns

ReturnType<S> | undefined[src]
import minOf
import { minOf } from "https://deno.land/std@0.147.0/collections/mod.ts?s=minOf";

Builds N-tuples of elements from the given N arrays with matching indices, stopping when the smallest array's end is reached Example:

import { zip } from "https://deno.land/std@0.147.0/collections/zip.ts";
import { assertEquals } from "https://deno.land/std@0.147.0/testing/asserts.ts";

const numbers = [ 1, 2, 3, 4 ];
const letters = [ 'a', 'b', 'c', 'd' ];
const pairs = zip(numbers, letters);

assertEquals(pairs, [
    [ 1, 'a' ],
    [ 2, 'b' ],
    [ 3, 'c' ],
    [ 4, 'd' ],
]);