Hard
What's the correct implementation for this simplified virtual DOM diffing algorithm?
1class VirtualDOM {2 static diff(oldNode, newNode, patches = [], index = 0) {3 // Node was removed4 if (!newNode) {5 patches.push({6 type: 'REMOVE',7 index8 });9 return;10 }1112 // Node was added13 if (!oldNode) {14 patches.push({15 type: 'ADD',16 node: newNode,17 index18 });19 return;20 }2122 // Compare and update nodes23 ______________________________24 ______________________________25 ______________________________2627 // Recursively diff children28 const maxLength = Math.max(29 oldNode.children?.length || 0,30 newNode.children?.length || 031 );3233 for (let i = 0; i < maxLength; i++) {34 VirtualDOM.diff(35 oldNode.children?.[i],36 newNode.children?.[i],37 patches,38 index + i + 139 );40 }4142 return patches;43 }44}