Files
common/packages/util/src/bn/min.ts
T
Jaco 6d795ecc5d Shared helper function for bn/bi min/max compares (#1527)
* Shared helper function for bn/bi min/max compares

* min/max test
2022-06-11 18:17:21 +03:00

46 lines
952 B
TypeScript

// Copyright 2017-2022 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { createCmp } from '../bi/helpers';
import { BN } from './bn';
/** @internal */
function gt (a: BN, b: BN): boolean {
return a.gt(b);
}
/** @internal */
function lt (a: BN, b: BN): boolean {
return a.lt(b);
}
/**
* @name bnMax
* @summary Finds and returns the highest value in an array of BNs.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnMax } from '@polkadot/util';
*
* bnMax([new BN(1), new BN(3), new BN(2)]).toString(); // => '3'
* ```
*/
export const bnMax = createCmp(gt);
/**
* @name bnMin
* @summary Finds and returns the smallest value in an array of BNs.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnMin } from '@polkadot/util';
*
* bnMin([new BN(1), new BN(3), new BN(2)]).toString(); // => '1'
* ```
*/
export const bnMin = createCmp(lt);