js-combinatorics
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -15,3 +15,3 @@ /** | ||
*/ | ||
export declare const version = "2.0.1"; | ||
export declare const version = "2.1.0"; | ||
/** | ||
@@ -113,3 +113,9 @@ * BigInt Workaround | ||
* negative `n` goes backwards | ||
* like `Array.prototype.at()` | ||
* @link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | ||
*/ | ||
at(n: anyint): Optional<U[]>; | ||
/** | ||
* an alias of `at` | ||
*/ | ||
nth(n: anyint): Optional<U[]>; | ||
@@ -142,3 +148,3 @@ /** | ||
constructor(seed: Iterable<T>, size?: number); | ||
nth(n: anyint): Optional<T[]>; | ||
at(n: anyint): Optional<T[]>; | ||
} | ||
@@ -158,3 +164,3 @@ /** | ||
bitwiseIterator(): Generator<T[], void, unknown>; | ||
nth(n: anyint): Optional<T[]>; | ||
at(n: anyint): Optional<T[]>; | ||
} | ||
@@ -167,3 +173,3 @@ /** | ||
constructor(seed: Iterable<T>, size?: number); | ||
nth(n: anyint): Optional<T[]>; | ||
at(n: anyint): Optional<T[]>; | ||
} | ||
@@ -175,3 +181,3 @@ /** | ||
constructor(seed: Iterable<T>); | ||
nth(n: anyint): Optional<T[]>; | ||
at(n: anyint): Optional<T[]>; | ||
} | ||
@@ -183,4 +189,4 @@ /** | ||
constructor(...args: Iterable<T>[]); | ||
nth(n: anyint): Optional<T[]>; | ||
at(n: anyint): Optional<T[]>; | ||
} | ||
export {}; |
@@ -15,3 +15,3 @@ /** | ||
*/ | ||
export const version = '2.0.1'; | ||
export const version = '2.1.0'; | ||
/** | ||
@@ -172,3 +172,3 @@ * calculates `P(n, k)`. | ||
for (let i = 0n; i < len; i++) | ||
yield it.nth(i); | ||
yield it.at(i); | ||
}(this, this.length); | ||
@@ -215,10 +215,15 @@ } | ||
* negative `n` goes backwards | ||
* like `Array.prototype.at()` | ||
* @link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | ||
*/ | ||
nth(n) { return []; } | ||
; | ||
at(n) { return undefined; } | ||
/** | ||
* an alias of `at` | ||
*/ | ||
nth(n) { return this.at(n); } | ||
/** | ||
* pick random element | ||
*/ | ||
sample() { | ||
return this.nth(randomInteger(this.length)); | ||
return this.at(randomInteger(this.length)); | ||
} | ||
@@ -246,3 +251,3 @@ /** | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -304,3 +309,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -331,3 +336,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -359,3 +364,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -384,3 +389,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -387,0 +392,0 @@ if (n === undefined) |
@@ -18,3 +18,3 @@ "use strict"; | ||
*/ | ||
exports.version = '2.0.1'; | ||
exports.version = '2.1.0'; | ||
/** | ||
@@ -181,3 +181,3 @@ * calculates `P(n, k)`. | ||
for (let i = 0n; i < len; i++) | ||
yield it.nth(i); | ||
yield it.at(i); | ||
}(this, this.length); | ||
@@ -224,10 +224,15 @@ } | ||
* negative `n` goes backwards | ||
* like `Array.prototype.at()` | ||
* @link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | ||
*/ | ||
nth(n) { return []; } | ||
; | ||
at(n) { return undefined; } | ||
/** | ||
* an alias of `at` | ||
*/ | ||
nth(n) { return this.at(n); } | ||
/** | ||
* pick random element | ||
*/ | ||
sample() { | ||
return this.nth(randomInteger(this.length)); | ||
return this.at(randomInteger(this.length)); | ||
} | ||
@@ -255,3 +260,3 @@ /** | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -314,3 +319,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -342,3 +347,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -371,3 +376,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -397,3 +402,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -400,0 +405,0 @@ if (n === undefined) |
{ | ||
"name": "js-combinatorics", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Simple combinatorics like power set, combination, and permutation in JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "combinatorics.js", |
@@ -50,3 +50,3 @@ [![ES2020](https://img.shields.io/badge/JavaScript-ES2020-blue.svg)](https://tc39.es/ecma262/2020/) | ||
```javascript | ||
import * as $C from 'https://cdn.jsdelivr.net/npm/js-combinatorics@2.0.1/combinatorics.min.js'; | ||
import * as $C from 'https://cdn.jsdelivr.net/npm/js-combinatorics@2.1.0/combinatorics.min.js'; | ||
``` | ||
@@ -88,3 +88,3 @@ | ||
randomInteger: [Function: randomInteger], | ||
version: '2.0.1' | ||
version: '2.1.0' | ||
} | ||
@@ -232,22 +232,22 @@ > [...new $C.Permutation('abcd')] | ||
#### `.nth()` | ||
#### `.at()` (or `.nth()`) | ||
And the object has `.nth(n)` method so you can random-access each element. This is the equivalent of subscript in `Array`. | ||
And the object has `.at(n)` method so you can random-access each element. This is the equivalent of subscript in `Array`. It was previously named `.nth()` but it was renamed to `.at()` ala `Array.prototype.at()` in ES2020. `.nth()` still available for backward compatibility. | ||
```javascript | ||
it.nth(0); // [ 'a', 'b', 'c', 'd' ]; | ||
it.nth(69); // [ 'a', 'd', 'c', 'h' ]; | ||
it.at(0); // [ 'a', 'b', 'c', 'd' ]; | ||
it.at(69); // [ 'a', 'd', 'c', 'h' ]; | ||
``` | ||
`nth()` accepts both `Number` and `BigInt`. | ||
`at()` accepts both `Number` and `BigInt`. | ||
```javascript | ||
it.nth(69n); // [ 'a', 'd', 'c', 'h' ]; | ||
it.at(69n); // [ 'a', 'd', 'c', 'h' ]; | ||
``` | ||
`nth()` also accepts negative indexes. In which case `n` is `(-n)th` element from `.length`. | ||
`at()` also accepts negative indexes. In which case `n` is `(-n)th` element from `.length`. | ||
```javascript | ||
it.nth(-1); // [ 'a', 'd', 'c', 'h' ] | ||
it.nth(-70); // [ 'a', 'b', 'c', 'd' ] | ||
it.at(-1); // [ 'a', 'd', 'c', 'h' ] | ||
it.at(-70); // [ 'a', 'b', 'c', 'd' ] | ||
``` | ||
@@ -257,3 +257,3 @@ | ||
And `.sample()` picks random element, which is defined as `.nth(randomInteger(.length))`. | ||
And `.sample()` picks random element, which is defined as `.at(randomInteger(.length))`. | ||
@@ -276,3 +276,3 @@ ```javascript | ||
```javascript | ||
it.nth(0); /* [ | ||
it.at(0); /* [ | ||
'a', 'b', 'c', 'd', 'e', 'f', | ||
@@ -284,3 +284,3 @@ 'g', 'h', 'i', 'j', 'k', 'l', | ||
] */ | ||
it.nth(9007199254740990); /* [ | ||
it.at(9007199254740990); /* [ | ||
'a', 'b', 'c', 'd', 'e', 'f', | ||
@@ -297,3 +297,3 @@ 'g', 'i', 'p', 'n', 'r', 'z', | ||
```javascript | ||
it.nth(9007199254740991n); /* [ | ||
it.at(9007199254740991n); /* [ | ||
'a', 'b', 'c', 'd', 'e', 'f', | ||
@@ -305,3 +305,3 @@ 'g', 'i', 'p', 'n', 'r', 'z', | ||
] */ | ||
it.nth(it.length - 1n); /* [ | ||
it.at(it.length - 1n); /* [ | ||
'z', 'y', 'x', 'w', 'v', 'u', | ||
@@ -361,3 +361,3 @@ 't', 's', 'r', 'q', 'p', 'o', | ||
it.length; // 371993326789901217467999448150835200000000n | ||
it.nth(371993326789901217467999448150835199999999n); /* [ | ||
it.at(371993326789901217467999448150835199999999n); /* [ | ||
'9', '8', '7', '6', '5', '4', '3', | ||
@@ -408,3 +408,3 @@ '2', '1', '0', 'z', 'y', 'x', 'w', | ||
it.length; // 100891344545564193334812497256n | ||
it.nth(100891344545564193334812497255n); /* [ | ||
it.at(100891344545564193334812497255n); /* [ | ||
50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, | ||
@@ -446,3 +446,3 @@ 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, | ||
it.length; // 18446744073709551616n | ||
it.nth(18446744073709551615n); /* [ | ||
it.at(18446744073709551615n); /* [ | ||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', | ||
@@ -492,3 +492,3 @@ 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', | ||
it.length; // 18446744073709551616n | ||
it.nth(18446744073709551615n); /* [ | ||
it.at(18446744073709551615n); /* [ | ||
'f', 'f', 'f', 'f', | ||
@@ -540,3 +540,3 @@ 'f', 'f', 'f', 'f', | ||
it.length; // 18446744073709551616n | ||
it.nth(18446744073709551615n); /* [ | ||
it.at(18446744073709551615n); /* [ | ||
'f', 'f', 'f', 'f', | ||
@@ -543,0 +543,0 @@ 'f', 'f', 'f', 'f', |
@@ -27,3 +27,3 @@ (function (factory) { | ||
*/ | ||
exports.version = '2.0.1'; | ||
exports.version = '2.1.0'; | ||
/** | ||
@@ -190,3 +190,3 @@ * calculates `P(n, k)`. | ||
for (let i = 0n; i < len; i++) | ||
yield it.nth(i); | ||
yield it.at(i); | ||
}(this, this.length); | ||
@@ -233,10 +233,15 @@ } | ||
* negative `n` goes backwards | ||
* like `Array.prototype.at()` | ||
* @link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | ||
*/ | ||
nth(n) { return []; } | ||
; | ||
at(n) { return undefined; } | ||
/** | ||
* an alias of `at` | ||
*/ | ||
nth(n) { return this.at(n); } | ||
/** | ||
* pick random element | ||
*/ | ||
sample() { | ||
return this.nth(randomInteger(this.length)); | ||
return this.at(randomInteger(this.length)); | ||
} | ||
@@ -264,3 +269,3 @@ /** | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -323,3 +328,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -351,3 +356,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -380,3 +385,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -406,3 +411,3 @@ if (n === undefined) | ||
} | ||
nth(n) { | ||
at(n) { | ||
n = this._check(n); | ||
@@ -409,0 +414,0 @@ if (n === undefined) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82359
9
1417