Skip to main content

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Downloads1/wk
Published2 years ago (0.215.0)
function minOf
minOf<T>(
array: Iterable<T>,
selector: (el: T) => number
): number | undefined

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.

Examples

Example 1

import { minOf } from "@std/collections/min_of";
import { assertEquals } from "@std/assert/assert_equals";

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

assertEquals(minCount, 2);

Type Parameters

Parameters

array: Iterable<T>
selector: (el: T) => number

Return Type

number | undefined
minOf<T>(
array: Iterable<T>,
selector: (el: T) => bigint
): bigint | undefined

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.

Examples

Example 1

import { minOf } from "@std/collections/min_of";
import { assertEquals } from "@std/assert/assert_equals";

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

assertEquals(minCount, 2n);

Type Parameters

Parameters

array: Iterable<T>
selector: (el: T) => bigint

Return Type

bigint | undefined

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/collections

Import symbol

import { minOf } from "@std/collections/min_of";
or

Import directly with a jsr specifier

import { minOf } from "jsr:@std/collections/min_of";