combinations
unknown
javascript
3 years ago
781 B
11
Indexable
const fs = require("fs"); const motherList = [ [9, 5, 2, 8, 9, 9], [3, 3, 5, 1, 4, 5, 1, 2], [1, 2, 9, 5, 4, 7, 3], [7, 5, 8, 8, 4], [5, 1, 4, 2], ]; function runAlgo(motherList) { for (let i = 0; i < motherList.length - 1; i++) { const list = motherList[i]; let nextList = motherList[i + 1]; if (i == 0) { motherList[i + 1] = motherList[i + 1].map((value) => list.map((value2) => [value2, value]) ); } else { motherList[i + 1] = motherList[i + 1].map((value) => list.flat(1).map((value2) => [...value2, value]) ); } } } runAlgo(motherList); const permutations = motherList[4].flat(1); console.log(JSON.stringify(permutations)); fs.writeFileSync("./combinations.json", JSON.stringify({ permutations }));
Editor is loading...