function maxOf
maxOf<T>(array: Iterable<T>,selector: (el: T) => number): number | undefinedApplies 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
Examples
Example 1
Example 1
import { maxOf } from "@std/collections/max_of"; import { assertEquals } from "@std/assert/assert_equals"; const inventory = [ { name: "mustard", count: 2 }, { name: "soy", count: 4 }, { name: "tomato", count: 32 }, ]; const maxCount = maxOf(inventory, (i) => i.count); assertEquals(maxCount, 32);
Type Parameters
TParameters
Return Type
number | undefinedmaxOf<T>(array: Iterable<T>,selector: (el: T) => bigint): bigint | undefinedApplies 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
Examples
Example 1
Example 1
import { maxOf } from "@std/collections/max_of"; import { assertEquals } from "@std/assert/assert_equals"; const inventory = [ { name: "mustard", count: 2n }, { name: "soy", count: 4n }, { name: "tomato", count: 32n }, ]; const maxCount = maxOf(inventory, (i) => i.count); assertEquals(maxCount, 32n);
Type Parameters
TParameters
Return Type
bigint | undefined