Last active
July 1, 2023 09:55
-
-
Save adamcameron/771b1ca6b2194f1214f704284beb91e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
data = [ | |
{ org: "A0", path: [0,0,0] }, | |
{ org: "A0->B1", path: [0,1,0] }, | |
{ org: "A0->B1->C1", path: [0,1,1] }, | |
{ org: "A0->B1->C2", path: [0,1,2] }, | |
{ org: "A1", path: [1,0,0] }, | |
{ org: "A1->D1", path: [1,1,0] }, | |
{ org: "A1->D1->E1", path: [1,1,1] }, | |
{ org: "A1->D1->E2", path: [1,1,2] }, | |
{ org: "A1->D2", path: [1,2,0] }, | |
{ org: "A1->D2->F1", path: [1,2,1] }, | |
{ org: "A1->D2->F2", path: [1,2,2] } | |
]; | |
base = {org=""} | |
stack =[base] | |
tree = data.reduce((tree, element) => { | |
element.children = [] | |
while (stack.len() > 1 && element.org.reFind("^#stack[1].org#")) { | |
stack.shift() | |
} | |
stack[1].children.append(element) | |
stack.prepend(element) | |
return tree | |
}, [base]) | |
tree.shift() | |
writeDump(tree) | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment