-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModifiedfata.ts
38 lines (31 loc) · 869 Bytes
/
Modifiedfata.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function generateCombinations(data) {
const keys = Object.keys(data);
const combinations = [];
function generateHelper(index, currentCombination) {
if (index === keys.length) {
combinations.push({ ...currentCombination });
return;
}
const key = keys[index];
const value = data[key];
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
currentCombination[key] = value[i];
generateHelper(index + 1, currentCombination);
}
} else {
currentCombination[key] = value;
generateHelper(index + 1, currentCombination);
}
}
generateHelper(0, {});
return combinations;
}
const data = {
Name: "abc",
Section: ["a", "b", "c", "d"],
Color: ["red", "green", "blue"],
Size: "large",
};
const combinations = generateCombinations(data);
console.log(combinations);