How to use the js-combinatorics.cartesianProduct function in js-combinatorics

To help you get started, we’ve selected a few js-combinatorics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / contracts / exchange / src / balance_stores / blockchain_balance_store.ts View on Github external
public async updateErc1155BalancesAsync(): Promise {
        const erc1155ContractsByAddress = _.zipObject(
            this._tokenContracts.erc1155.map(contract => contract.address),
            this._tokenContracts.erc1155,
        );

        for (const [tokenAddress, { fungible, nonFungible }] of Object.entries(this._tokenIds.erc1155)) {
            const contract = erc1155ContractsByAddress[tokenAddress];
            const tokenIds = [...fungible, ...nonFungible];
            if (this._ownerAddresses.length === 0 || tokenIds.length === 0) {
                continue;
            }

            const [_tokenIds, _tokenOwners] = _.unzip(
                combinatorics.cartesianProduct(tokenIds, this._ownerAddresses).toArray(),
            );
            const balances = await contract
                .balanceOfBatch(_tokenOwners as string[], _tokenIds as BigNumber[])
                .callAsync();

            let i = 0;
            for (const tokenOwner of this._ownerAddresses) {
                // Fungible tokens
                _.set(this.balances.erc1155, [tokenOwner, tokenAddress, 'fungible'], {});
                for (const tokenId of fungible) {
                    _.set(
                        this.balances.erc1155,
                        [tokenOwner, tokenAddress, 'fungible', tokenId.toString()],
                        balances[i++],
                    );
                }
github DefinitelyTyped / DefinitelyTyped / js-combinatorics / js-combinatorics-tests.ts View on Github external
const filteredbaseNs:string[][] = baseN.filter((i:string[]) => i.length > 0);
const allbaseNs:string[][] = baseN.toArray();
const baseNsCount = baseN.length;
const nthbaseN:string[] = baseN.nth(3);

const cartesianProduct1 = Combinatorics.cartesianProduct(["a", "b", "c"]);
const nextCartesianProduct1:[string] = cartesianProduct1.next();
cartesianProduct1.forEach((i:[string]) => console.log(i));
const cartesianProduct1sLengths:number[] = cartesianProduct1.map((i:[string]) => i.length);
const filteredCartesianProduct1s:[string][] = cartesianProduct1.filter((i:[string]) => i.length > 0);
const allCartesianProduct1s:[string][] = cartesianProduct1.toArray();
const cartesianProduct1sCount = cartesianProduct1.length;
const nthCartesianProduct1:[string] = cartesianProduct1.nth(3);
const cartesianProduct1ByCoords:[string] = cartesianProduct1.get(1);

const cartesianProduct2 = Combinatorics.cartesianProduct(["a", "b", "c"], [1, 2, 3]);
const nextCartesianProduct2:[string, number] = cartesianProduct2.next();
cartesianProduct2.forEach((i:[string, number]) => console.log(i));
const cartesianProduct2sLengths:number[] = cartesianProduct2.map((i:[string, number]) => i.length);
const filteredCartesianProduct2s:[string, number][] = cartesianProduct2.filter((i:[string, number]) => i.length > 0);
const allCartesianProduct2s:[string, number][] = cartesianProduct2.toArray();
const cartesianProduct2sCount = cartesianProduct2.length;
const nthCartesianProduct2:[string, number] = cartesianProduct2.nth(3);
const cartesianProduct2ByCoords:[string, number] = cartesianProduct2.get(1, 1);

const cartesianProduct3 = Combinatorics.cartesianProduct(["a", "b", "c"], [1, 2, 3], [true, false]);
const nextCartesianProduct3:[string, number, boolean] = cartesianProduct3.next();
cartesianProduct3.forEach((i:[string, number, boolean]) => console.log(i));
const cartesianProduct3sLengths:number[] = cartesianProduct3.map((i:[string, number, boolean]) => i.length);
const filteredCartesianProduct3s:[string, number, boolean][] = cartesianProduct3.filter((i:[string, number, boolean]) => i.length > 0);
const allCartesianProduct3s:[string, number, boolean][] = cartesianProduct3.toArray();
const cartesianProduct3sCount = cartesianProduct3.length;
github DefinitelyTyped / DefinitelyTyped / js-combinatorics / js-combinatorics-tests.ts View on Github external
const allCartesianProduct1s:[string][] = cartesianProduct1.toArray();
const cartesianProduct1sCount = cartesianProduct1.length;
const nthCartesianProduct1:[string] = cartesianProduct1.nth(3);
const cartesianProduct1ByCoords:[string] = cartesianProduct1.get(1);

const cartesianProduct2 = Combinatorics.cartesianProduct(["a", "b", "c"], [1, 2, 3]);
const nextCartesianProduct2:[string, number] = cartesianProduct2.next();
cartesianProduct2.forEach((i:[string, number]) => console.log(i));
const cartesianProduct2sLengths:number[] = cartesianProduct2.map((i:[string, number]) => i.length);
const filteredCartesianProduct2s:[string, number][] = cartesianProduct2.filter((i:[string, number]) => i.length > 0);
const allCartesianProduct2s:[string, number][] = cartesianProduct2.toArray();
const cartesianProduct2sCount = cartesianProduct2.length;
const nthCartesianProduct2:[string, number] = cartesianProduct2.nth(3);
const cartesianProduct2ByCoords:[string, number] = cartesianProduct2.get(1, 1);

const cartesianProduct3 = Combinatorics.cartesianProduct(["a", "b", "c"], [1, 2, 3], [true, false]);
const nextCartesianProduct3:[string, number, boolean] = cartesianProduct3.next();
cartesianProduct3.forEach((i:[string, number, boolean]) => console.log(i));
const cartesianProduct3sLengths:number[] = cartesianProduct3.map((i:[string, number, boolean]) => i.length);
const filteredCartesianProduct3s:[string, number, boolean][] = cartesianProduct3.filter((i:[string, number, boolean]) => i.length > 0);
const allCartesianProduct3s:[string, number, boolean][] = cartesianProduct3.toArray();
const cartesianProduct3sCount = cartesianProduct3.length;
const nthCartesianProduct3:[string, number, boolean] = cartesianProduct3.nth(3);
const cartesianProduct3ByCoords:[string, number, boolean] = cartesianProduct3.get(1, 1);

const cartesianProductAny = Combinatorics.cartesianProduct(["a", 1, true], [false, 2, "b"]);
const nextCartesianProductAny:any[] = cartesianProductAny.next();
cartesianProductAny.forEach((i:any[]) => console.log(i));
const cartesianProductAnysLengths:number[] = cartesianProductAny.map((i:any[]) => i.length);
const filteredCartesianProductAnys:any[][] = cartesianProductAny.filter((i:any[]) => i.length > 0);
const allCartesianProductAnys:any[][] = cartesianProductAny.toArray();
const cartesianProductAnysCount = cartesianProductAny.length;
github 0xProject / 0x-monorepo / contracts / test-utils / src / combinatorial_utils.ts View on Github external
export function testCombinatoriallyWithReferenceFunc(
    name: string,
    referenceFuncAsync: (...args: any[]) => Promise,
    testFuncAsync: (...args: any[]) => Promise,
    allValues: any[],
): void {
    const testCases = combinatorics.cartesianProduct(...allValues);
    let counter = 0;
    testCases.forEach(async testCase => {
        counter += 1;
        it(`${name} ${counter}/${testCases.length}`, async () => {
            await testWithReferenceFuncAsync(referenceFuncAsync, testFuncAsync, testCase as any);
        });
    });
}
github DefinitelyTyped / DefinitelyTyped / types / js-combinatorics / js-combinatorics-tests.ts View on Github external
const filteredbaseNs:string[][] = baseN.filter((i:string[]) => i.length > 0);
const allbaseNs:string[][] = baseN.toArray();
const baseNsCount = baseN.length;
const nthbaseN:string[] = baseN.nth(3);

const cartesianProduct1 = Combinatorics.cartesianProduct(["a", "b", "c"]);
const nextCartesianProduct1:[string] = cartesianProduct1.next();
cartesianProduct1.forEach((i:[string]) => console.log(i));
const cartesianProduct1sLengths:number[] = cartesianProduct1.map((i:[string]) => i.length);
const filteredCartesianProduct1s:[string][] = cartesianProduct1.filter((i:[string]) => i.length > 0);
const allCartesianProduct1s:[string][] = cartesianProduct1.toArray();
const cartesianProduct1sCount = cartesianProduct1.length;
const nthCartesianProduct1:[string] = cartesianProduct1.nth(3);
const cartesianProduct1ByCoords:[string] = cartesianProduct1.get(1);

const cartesianProduct2 = Combinatorics.cartesianProduct(["a", "b", "c"], [1, 2, 3]);
const nextCartesianProduct2:[string, number] = cartesianProduct2.next();
cartesianProduct2.forEach((i:[string, number]) => console.log(i));
const cartesianProduct2sLengths:number[] = cartesianProduct2.map((i:[string, number]) => i.length);
const filteredCartesianProduct2s:[string, number][] = cartesianProduct2.filter((i:[string, number]) => i.length > 0);
const allCartesianProduct2s:[string, number][] = cartesianProduct2.toArray();
const cartesianProduct2sCount = cartesianProduct2.length;
const nthCartesianProduct2:[string, number] = cartesianProduct2.nth(3);
const cartesianProduct2ByCoords:[string, number] = cartesianProduct2.get(1, 1);

const cartesianProduct3 = Combinatorics.cartesianProduct(["a", "b", "c"], [1, 2, 3], [true, false]);
const nextCartesianProduct3:[string, number, boolean] = cartesianProduct3.next();
cartesianProduct3.forEach((i:[string, number, boolean]) => console.log(i));
const cartesianProduct3sLengths:number[] = cartesianProduct3.map((i:[string, number, boolean]) => i.length);
const filteredCartesianProduct3s:[string, number, boolean][] = cartesianProduct3.filter((i:[string, number, boolean]) => i.length > 0);
const allCartesianProduct3s:[string, number, boolean][] = cartesianProduct3.toArray();
const cartesianProduct3sCount = cartesianProduct3.length;
github DefinitelyTyped / DefinitelyTyped / js-combinatorics / js-combinatorics-tests.ts View on Github external
const allCartesianProduct2s:[string, number][] = cartesianProduct2.toArray();
const cartesianProduct2sCount = cartesianProduct2.length;
const nthCartesianProduct2:[string, number] = cartesianProduct2.nth(3);
const cartesianProduct2ByCoords:[string, number] = cartesianProduct2.get(1, 1);

const cartesianProduct3 = Combinatorics.cartesianProduct(["a", "b", "c"], [1, 2, 3], [true, false]);
const nextCartesianProduct3:[string, number, boolean] = cartesianProduct3.next();
cartesianProduct3.forEach((i:[string, number, boolean]) => console.log(i));
const cartesianProduct3sLengths:number[] = cartesianProduct3.map((i:[string, number, boolean]) => i.length);
const filteredCartesianProduct3s:[string, number, boolean][] = cartesianProduct3.filter((i:[string, number, boolean]) => i.length > 0);
const allCartesianProduct3s:[string, number, boolean][] = cartesianProduct3.toArray();
const cartesianProduct3sCount = cartesianProduct3.length;
const nthCartesianProduct3:[string, number, boolean] = cartesianProduct3.nth(3);
const cartesianProduct3ByCoords:[string, number, boolean] = cartesianProduct3.get(1, 1);

const cartesianProductAny = Combinatorics.cartesianProduct(["a", 1, true], [false, 2, "b"]);
const nextCartesianProductAny:any[] = cartesianProductAny.next();
cartesianProductAny.forEach((i:any[]) => console.log(i));
const cartesianProductAnysLengths:number[] = cartesianProductAny.map((i:any[]) => i.length);
const filteredCartesianProductAnys:any[][] = cartesianProductAny.filter((i:any[]) => i.length > 0);
const allCartesianProductAnys:any[][] = cartesianProductAny.toArray();
const cartesianProductAnysCount = cartesianProductAny.length;
const nthCartesianProductAny:any[] = cartesianProductAny.nth(3);
const cartesianProductAnyByCoords:any[] = cartesianProductAny.get(1, 1);

const version:string = Combinatorics.VERSION;
github Rcomian / bunyan-rotating-file-stream / test / stress.js View on Github external
function expandCombinations() {
    var combi = Combinatorics.cartesianProduct(
        ['1h', '1d', 'X'],
        [0, 1, '1m', '10m'],
        [0, 10],
        [0, '10m'],
        [true, false],
        ['basic.log', 'withinsert-%N-file.log', 'datestamped-%Y-%m-%d.log', 'datestampinsterted-%Y-%m-%d-%N-file.log', 'timestamped-%Y-%m-%d-%H-%M-%S.log', 'timestampinserted-%Y-%m-%d-%H-%M-%S-%N-file.log']
    );

    var streams = [];
    var dedupe = {};
    combi.toArray().forEach(function (streamdef) {
        var name = streamdef.join('-');

        dedupe[name] = 1;

        var config = {
github kuzzleio / koncorde / lib / transform / canonical.js View on Github external
}
            else {
              ors.push(conds);
            }
          }
          else {
            subresult.push(sub);
          }
        }
      }

      if (ors.length === 0 && subresult.length > 0) {
        result.push(subresult);
      }
      else if (ors.length > 0) {
        const combinations = Combinatorics.cartesianProduct(...ors);
        let n = combinations.length;

        while (n) {
          n--;
          result.push(subresult.concat(combinations.next()));
        }
      }

    });
github cypir / mhwbuild / src / util / calculate.js View on Github external
//for each combination, get the arrays and do a cartesian product
      //we start at 1 because first item is empty set
      for (let i = 1; i < powerSet.length; i++) {
        let combination = powerSet[i];

        //we need to find the cartesian product of all combinations,
        //so for 2 pieces (head and arms), we have 0,1,01, which are
        //only head, only arm, head and arms
        let toFindProduct = [];

        combination.forEach(index => {
          toFindProduct.push(categorizedByPartArray[index]);
        });

        //then we use the spread operator to break the array of arrays into individual arrays
        let cp = Combinatrics.cartesianProduct(...toFindProduct);

        //use spread because its nested one level too deep
        allSets.push(...cp.toArray());
      }

      //sets that match the level criteria
      let criteriaSets = [];
      allSets.forEach(set => {
        //iterate through the set and figure out if we meet the minimum criteria
        let sum = 0;
        set.forEach(piece => {
          piece.skills.forEach(skill => {
            if (skill.name.toLowerCase() === skillWanted.name.toLowerCase()) {
              sum += skill.level;
            }
          });