Created
August 12, 2022 02:40
-
-
Save RuNpiXelruN/96402ef2c807529e2df7cd19e7a2d11a to your computer and use it in GitHub Desktop.
Depth first search
This file contains hidden or 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
export function getActionBox(boxes: any[], id: number) { | |
let found = null | |
let i = boxes.length | |
while (i--) { | |
if (boxes[i].id.self === id) { | |
found = boxes[i] | |
return found | |
} | |
let j = boxes[i].children.length | |
while (j--) { | |
found = depthFirstBoxSearch(boxes[i].children[j], id) | |
} | |
} | |
return found | |
} | |
function depthFirstBoxSearch(boxObj: AutomationBox, id: number): AutomationBox | null { | |
if (boxObj.id.self === id) { | |
return boxObj | |
} | |
if (!!boxObj.children.length) { | |
let i = boxObj.children.length | |
while (i--) { | |
let found = depthFirstBoxSearch(boxObj.children[i], id) | |
if (found) return found | |
} | |
} | |
return null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment