UNPKG

786 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import { assert } from "../assert.js";
4
5function gt(a, b) {
6 return a > b;
7}
8
9function lt(a, b) {
10 return a < b;
11}
12
13function find(items, cmp) {
14 assert(items.length >= 1, 'Must provide one or more bigint arguments');
15 let result = items[0];
16
17 for (let i = 1; i < items.length; i++) {
18 if (cmp(items[i], result)) {
19 result = items[i];
20 }
21 }
22
23 return result;
24}
25/**
26 * @name nMax
27 * @summary Finds and returns the highest value in an array of bigint.
28 */
29
30
31export function nMax(...items) {
32 return find(items, gt);
33}
34/**
35 * @name nMin
36 * @summary Finds and returns the lowest value in an array of bigint.
37 */
38
39export function nMin(...items) {
40 return find(items, lt);
41}
\No newline at end of file