Last active
November 22, 2018 14:48
-
-
Save almost/86231d372c1087ad662a43d4acc7f27a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tree { | |
constructor(value, left, right) { | |
this.left = left; | |
this.value = value; | |
this.right = right; | |
} | |
} | |
function* iterateTree(tree) { | |
// ????? | |
} | |
var myTree = new Tree( | |
1, | |
new Tree(2, new Tree(3), new Tree(4)), | |
new Tree(5, new Tree(6), new Tree(7)) | |
); | |
for (let value of iterateTree(myTree)) { | |
console.log(value); | |
} | |
// Desired output: | |
// 1 | |
// 2 | |
// 3 | |
// 4 | |
// 5 | |
// 6 | |
// 7 | |
// // Bonus question: Can you make this work?: | |
// // | |
// for(let value of myTree) { | |
// console.log(value); | |
// } | |
// // | |
// // Hint1: The Symbol.iterator property of a class is meant to return an iterator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment