loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const dfs = (tree) => {
  const [name, children] = tree;
  console.log(name);
  if (!children) {
    return;
  }
  return children.map(dfs);
};

const tree = ['A', [
  ['B', [['E'], ['F']]],
  ['C'],
  ['D', [['G'], ['J']]],
]];

dfs(tree);
Native Browser JavaScript