Refactor rendering
This commit is contained in:
parent
9b47d56d8f
commit
c892ca2d01
38 changed files with 511 additions and 429 deletions
31
frontend/src/scripts/helper/get-combinations.ts
Normal file
31
frontend/src/scripts/helper/get-combinations.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
export const getCombinations = (
|
||||
values: Array<Array<number>>
|
||||
): Array<Array<number>> => {
|
||||
if (!values.every((a) => a.length > 0)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const result: Array<Array<number>> = [];
|
||||
const counters = values.map((_) => 0);
|
||||
|
||||
const increaseCounter = (i: number) => {
|
||||
if (i >= counters.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
counters[i]++;
|
||||
|
||||
if (counters[i] >= values[i].length) {
|
||||
counters[i] = 0;
|
||||
return increaseCounter(i + 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
do {
|
||||
result.push(values.map((v, i) => v[counters[i]]));
|
||||
} while (increaseCounter(0));
|
||||
|
||||
return result;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue