Added bigCombination to js-combinatorics

This commit is contained in:
Teun Duynstee
2018-12-03 21:05:37 +01:00
parent 4da52f569b
commit 7643f499bc
2 changed files with 17 additions and 0 deletions
+8
View File
@@ -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();