export const findPathById = (tree, id, getId) => {
    const stack = [...tree];
    const visited = new Set();
    const path = [];
    while (stack.length !== 0) {
        const node = stack.at(-1);
        const currentId = getId(node);
        if (visited.has(currentId)) {
            stack.pop();
            path.pop();
            continue;
        }
        path.push(currentId);
        visited.add(currentId);
        if (currentId === id) {
            break;
        }
        if (node.children !== undefined) {
            node.children.map((child) => stack.push(child));
        }
    }
    return path;
};
