Merge pull request #31026 from Teun/big-combination

js-combinatorics: Added bigCombination function
This commit is contained in:
Nathan Shively-Sanders
2018-12-18 10:09:01 -08:00
committed by GitHub
2 changed files with 18 additions and 1 deletions
+9 -1
View File
@@ -1,4 +1,4 @@
// Type definitions for js-combinatorics v0.5.0
// Type definitions for js-combinatorics v0.5.4
// Project: https://github.com/dankogai/js-combinatorics
// Definitions by: Vasya Aksyonov <https://github.com/outring>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -92,6 +92,14 @@ declare namespace __Combinatorics {
*/
function combination<T>(a:T[], n?:number):IGenerator<T[]>;
/**
* Generates the combination of array with n elements, which
* also supports larger sets of elements.
* When n is ommited, the length of the array is used.
* Somewhat slower than combination()
*/
function bigCombination<T>(a:T[], n?:number):IGenerator<T[]>;
/**
* Generates the permutation of array with n elements.
* When n is ommited, the length of the array is used.
@@ -25,6 +25,15 @@ const filteredCombinations:string[][] = combination.filter((i:string[]) => i.len
const allCombinations:string[][] = combination.toArray();
const combinationsCount = combination.length;
const limitedBigCombination = Combinatorics.bigCombination(["a", "b", "c"], 2);
const bigCombination = Combinatorics.bigCombination(["a", "b", "c"]);
const nextBigCombination:string[] = bigCombination.next();
bigCombination.forEach((i:string[]) => console.log(i));
const bigCombinationsLengths:number[] = bigCombination.map((i:string[]) => i.length);
const filteredBigCombinations:string[][] = bigCombination.filter((i:string[]) => i.length > 0);
const allBigCombinations:string[][] = bigCombination.toArray();
const bigCombinationsCount = bigCombination.length;
const limitedPermutation = Combinatorics.permutation(["a", "b", "c"], 2);
const permutation = Combinatorics.permutation(["a", "b", "c"]);
const nextPermutation:string[] = permutation.next();