Interview Question

Front End Engineer Interview

-London, England, England

Facebook

Given two identical DOM trees (not the same one), and a node from one of them find the node in the other one.

Answer

Interview Answer

1 Answer

0

const findCorrespondingNode = (rootA, rootB, target) => { // your code here let directions = [] let found = false function findNode(root, target, track){ if(!root) return if(root === target){ directions = [...track] found = true return } for(let i= 0; i <div> <div> <div></div> </div> <div> </div> <div> <div> <p></p> </div> </div> <div> </div>` const B = A.cloneNode(true) const node1 = A.querySelector('#node1') const node2 = A.querySelector('#node2') const node1Target = B.querySelector('#node1') const node2Target = B.querySelector('#node2') console.log(findCorrespondingNode(A, B, node1Target))</div>

My DFS solution on

Add Answers or Comments

To comment on this, Sign In or Sign Up.