Function maxOf
- max
Of <T>(array, selector): number | undefined Type Parameters
Parameters
Returns number | undefined
The largest value of the given function or undefined if there are no elements.
Example: Basic usage
import { maxOf } from "@std/collections/max-of";
import { assertEquals } from "@std/assert";
const inventory = [
{ name: "mustard", count: 2 },
{ name: "soy", count: 4 },
{ name: "tomato", count: 32 },
];
const maxCount = maxOf(inventory, (item) => item.count);
assertEquals(maxCount, 32);- max
Of <T>(array, selector): bigint | undefined Applies the given selector to all elements of the provided collection and returns the max value of all elements. If an empty array is provided the function will return undefined.
Type Parameters
Parameters
Returns bigint | undefined
The first element that is the largest value of the given function or undefined if there are no elements.
Example: Basic usage
import { maxOf } from "@std/collections/max-of";
import { assertEquals } from "@std/assert";
const inventory = [
{ name: "mustard", count: 2n },
{ name: "soy", count: 4n },
{ name: "tomato", count: 32n },
];
const maxCount = maxOf(inventory, (i) => i.count);
assertEquals(maxCount, 32n);
Applies the given selector to all elements of the provided collection and returns the max value of all elements. If an empty array is provided the function will return undefined.