46 lines
952 B
TypeScript
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);
|