@polkadot/util
Version: 
A collection of useful utilities for @polkadot
30 lines (29 loc) • 731 B
JavaScript
import { createCmp } from '../bi/helpers.js';
/**
 * @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 = /*#__PURE__*/ createCmp((a, b) => a.gt(b));
/**
 * @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 = /*#__PURE__*/ createCmp((a, b) => a.lt(b));