Hard
Implement a tree traversal iterator that supports different traversal strategies. What's the correct implementation?
1class TreeNode {2 constructor(value) {3 this.value = value;4 this.left = null;5 this.right = null;6 }7}89class TreeIterator {10 constructor(root, strategy = 'inorder') {11 this.root = root;12 this.strategy = strategy;13 }1415 // Missing implementation16 [Symbol.iterator]() {17 ____________________18 ____________________19 ____________________20 ____________________21 }22}2324// Usage:25const tree = new TreeNode(1);26tree.left = new TreeNode(2);27tree.right = new TreeNode(3);28tree.left.left = new TreeNode(4);29tree.left.right = new TreeNode(5);3031for (const value of new TreeIterator(tree, 'inorder')) {32 console.log(value); // Should output: 4, 2, 5, 1, 333}