mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-01-27 15:22:56 +08:00
chore: refactor getOutgoers
This commit is contained in:
parent
b7492c1c55
commit
41743f1ff0
@ -6,20 +6,20 @@ export const getOutgoers = (
|
||||
): [NodeData[], string[]] => {
|
||||
const outgoerNodes: NodeData[] = [];
|
||||
const matchingNodes: string[] = [];
|
||||
|
||||
if (parent.includes(nodeId)) {
|
||||
const initialParentNode = nodes.find(n => n.id === nodeId);
|
||||
if (initialParentNode) outgoerNodes.push(initialParentNode);
|
||||
}
|
||||
|
||||
const runner = (nodeId: string) => {
|
||||
const outgoerIds = edges.filter(e => e.from === nodeId).map(e => e.to);
|
||||
|
||||
if (parent.includes(nodeId)) {
|
||||
const initialParentNode = nodes.find(n => n.id === nodeId);
|
||||
if (initialParentNode) outgoerNodes.push(initialParentNode);
|
||||
}
|
||||
|
||||
const nodeList = nodes.filter(n => {
|
||||
if (parent.includes(n.id) && !matchingNodes.includes(n.id))
|
||||
matchingNodes.push(n.id);
|
||||
return outgoerIds.includes(n.id) && !parent.includes(n.id);
|
||||
});
|
||||
|
||||
|
||||
outgoerNodes.push(...nodeList);
|
||||
nodeList.forEach(node => runner(node.id));
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user