cardinal-power
v1.0.0
Published
Returns the total number of possible combinations for a given cardinality and sequence length using BigInt exponentiation
Maintainers
Readme
cardinal-power
Canonical URL:
https://alexstevovich.com/a/cardinal-power-nodejs
Software URL:
https://midnightcitylights.com/software/cardinal-power-nodejs
Computes the total number of unique combinations given a cardinality (the number of distinct symbols or values)
and a sequence length, using BigInt exponentiation for mathematical precision.
Installation
npm install cardinal-powerExample
import cardinalPower from 'cardinal-power';
console.log(cardinalPower(2, 8)); // 256n
console.log(cardinalPower(10, 6)); // 1000000n
console.log(cardinalPower(26, 5)); // 11881376nFunction
cardinalPower(cardinality, length)
Returns the total number of possible sequences of a given length using a set of symbols with the specified cardinality.
| Parameter | Type | Description |
| ------------- | -------- | ------------------------------------------------------------------ |
| cardinality | number | Number of unique symbols or elements (must be a positive integer). |
| length | number | Length of the sequence (must be a non-negative integer). |
Returns
| Type | Description |
| -------- | ------------------------------------------------- |
| BigInt | The total number of possible unique combinations. |
Notes
- Uses BigInt to handle extremely large exponents safely.
- Throws descriptive errors for invalid or non-integer inputs.
- Useful for encoding, cryptography, data compression, or combinatorial analysis.
- Minimal and dependency-free.
License
Licensed under the Apache License 2.0.
