Created
January 19, 2017 04:09
-
-
Save zhuzhuaicoding/4d1c4fcbeacf8d980e82df477e25cce8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function* iterTree (tree) { | |
if (Array.isArray(tree)) { | |
for (var i = tree.length - 1; i >= 0; i--) { | |
yield* iterTree(tree[i]) | |
} | |
} else { | |
yield tree | |
} | |
} | |
const tree = [ 'a', ['b', 'c'], ['d', 'e'] ]; | |
for(let x of iterTree(tree)) { | |
console.log(x); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment