26 lines
643 B
TypeScript
26 lines
643 B
TypeScript
// Copyright 2017-2020 @polkadot/util authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import BN from 'bn.js';
|
|
|
|
import assert from '../assert';
|
|
|
|
/**
|
|
* @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 default function min (...items: BN[]): BN {
|
|
assert(items && items.length >= 1, 'Must provide one or more BN arguments');
|
|
|
|
return items.reduce((acc: BN, val: BN) => BN.min(acc, val), items[0]);
|
|
}
|