Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Elements without children
- const dfs = tree => {
- const [element, children] = tree;
- return !children ? undefined : children.map(dfs);
- };
- dfs(['A',
- [
- ['B', [['E'], ['F']]],
- ['C'],
- ['D', [['G'], ['J']]],
- ]
- ]);
- //[[ undefined, undefined ], undefined, [ undefined, undefined ]]
Add Comment
Please, Sign In to add comment