Skip to main content

Function: max()

max(iterable: IterableResolvable <NumberResolvable>): number | null

Consumes the iterable and returns the highest number element. If the iterable is empty, or contains only non-number values, it returns null.

Parameters

ParameterTypeDescription
iterableIterableResolvable <NumberResolvable>An iterator of number values to determine the maximum value of.

Returns

number | null

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

Example

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

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

Remarks

This function consumes the entire iterator.

Source

projects/utilities/packages/iterator-utilities/src/lib/max.ts:24