Skip to main content

Function: min()

min<ElementType>(iterable: IterableResolvable<ElementType>): ElementType | null

Consumes the iterable and returns the lowest number element. If the iterable is empty, it returns null.

This function uses the default comparator (lexicographically), which means it will compare the elements as strings. If this is undesirable, use minBy instead.

Type Parameters

Type Parameter
ElementType

Parameters

ParameterTypeDescription
iterableIterableResolvable<ElementType>An iterator of number values to determine the minimum value of.

Returns

ElementType | null

The minimum value in the input iterator, or null if the iterator is empty or contains only non-number values.

Seealso

minBy for a version that allows custom comparators.

Seealso

minByKey for a version that allows custom key extractors.

Example

import { min } from '@sapphire/iterator-utilities';

const iterable = [1, 2, 3, 4, 5];
console.log(min(iterable));
// Output: 1

Remarks

This function consumes the entire iterator.

Defined in

projects/utilities/packages/iterator-utilities/src/lib/min.ts:31