loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const reduce = (f, tree, acc) => {
  const [, children] = tree;
  const newAcc = f(acc, tree);

  if (!children) {
    return newAcc;
  }
  return children.reduce((iAcc, n) => reduce(f, n, iAcc), newAcc);
};

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

reduce((acc) => acc + 1, tree, 0);
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie