Open afizzycola opened 3 years ago
const testStack = ["AND", 2, "Activity_10ttrdj", "OR", 2, "Activity_17ymcwz", "Activity_0nyqi0b"];
function generatePathsFromStack2(stack = []) {
//flaten the ANDs
let paths = [];
const andI = stack.indexOf("AND");
const numOfAndAugs = stack[andI + 1];
stack.splice(andI, 2);
console.log(stack);
//resolve the ORs
const orI = stack.indexOf("OR");
const numOfOrAugs = stack[orI + 1];
orSet = stack.splice(orI, orI + 2 + numOfOrAugs);
console.log(orSet,numOfOrAugs );
orArray = orSet.slice(2, 2 + numOfOrAugs);
console.log(orArray);
for (let i = 0; i < numOfOrAugs; i++) {
paths.push(new Set().add(orArray[i]));
}
//apend ANDs to paths
const finalThingToAdd = stack.shift();
paths.forEach( path => {
path.add(finalThingToAdd);
})
console.log(paths);
console.log(stack);
}
generatePathsFromStack2(testStack);