UNPKG

1.17 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.nMax = nMax;
7exports.nMin = nMin;
8
9var _assert = require("../assert");
10
11// Copyright 2017-2022 @polkadot/util authors & contributors
12// SPDX-License-Identifier: Apache-2.0
13function gt(a, b) {
14 return a > b;
15}
16
17function lt(a, b) {
18 return a < b;
19}
20
21function find(items, cmp) {
22 (0, _assert.assert)(items.length >= 1, 'Must provide one or more bigint arguments');
23 let result = items[0];
24
25 for (let i = 1; i < items.length; i++) {
26 if (cmp(items[i], result)) {
27 result = items[i];
28 }
29 }
30
31 return result;
32}
33/**
34 * @name nMax
35 * @summary Finds and returns the highest value in an array of bigint.
36 */
37
38
39function nMax() {
40 for (var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++) {
41 items[_key] = arguments[_key];
42 }
43
44 return find(items, gt);
45}
46/**
47 * @name nMin
48 * @summary Finds and returns the lowest value in an array of bigint.
49 */
50
51
52function nMin() {
53 for (var _len2 = arguments.length, items = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
54 items[_key2] = arguments[_key2];
55 }
56
57 return find(items, lt);
58}
\No newline at end of file