Unique-combinatorics
Introduction
With unique Combinatorics you will be able to generate combinations of any elements. Can generate the combinations so that all return values are unique.
example: you have the string "AAB" that you want all the combinations different combinations for, but you don't want "AAB" twice. Then it should look like the following.
'A' 'A' 'B' 'A' 'B' 'A' 'B' 'A' 'A'
Basic usage
Installation
npm install --save unique-combinatorics
Getting started
Example 1
const uniques = ; const u = uniques; for let cmb of u console; //logs:/*** [ 'A', 'A', 'B' ],** [ 'A', 'B', 'A' ],** [ 'B', 'A', 'A' ]*/
Example 2
const uniques = ; const u = uniques; console; // [0, "A", 2, 3]console; // [0, "A", 3, 2]
Example 3
In this example it looks like you get the same combination twice, but because both arrays have different references they act like they are different. But if you use the same reference again, the second won't be unique and as you see in the example there is only one combination.
const uniques = ; //both arrays have unique referencesconst arr1 = "A" "B";const arr2 = "A" "B";const u = uniques;const u2 = uniques; for let cmb of u console; //logs:/*** ["A", "B"], ["A", "B"]** ["A", "B"], ["A", "B"]*/ for let cmb of u2 console;// Both arrays have the same reference//logs:/*** ["A", "B"], ["A", "B"]*/
Documentation
uniques.permutation()
uniques.permutation(items: any[] | String)
Parameters
items: any[] | String
items: Array
items should be an array of items that can have any value. These are the items which will be placed differently in every iteration.
items: String
if you put a string as the item argurment it will split the string essentially if you give it the string "AAB"
it will convert i to ["A", "A", "B"]
and do exactly the same as if it was an array.
Returns
an iterable (Object)