MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / combinations

Function combinations

test/compute-engine/diophantine.test.ts:115–125  ·  view source on GitHub ↗
(pool: T[], k: number)

Source from the content-addressed store, hash-verified

113}
114
115function* combinations<T>(pool: T[], k: number): Generator<T[]> {
116 if (k === 0) {
117 yield [];
118 return;
119 }
120 for (let i = 0; i <= pool.length - k; i++) {
121 for (const rest of combinations(pool.slice(i + 1), k - 1)) {
122 yield [pool[i], ...rest];
123 }
124 }
125}
126
127/**
128 * Invert the affine map `x = base + coef·t`: find integer parameters `t`

Callers 1

invertParamsFunction · 0.70

Calls 1

sliceMethod · 0.65

Tested by

no test coverage detected