Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Last active July 1, 2023 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcameron/771b1ca6b2194f1214f704284beb91e2 to your computer and use it in GitHub Desktop.
Save adamcameron/771b1ca6b2194f1214f704284beb91e2 to your computer and use it in GitHub Desktop.
<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