function average({ value, children = [] }, result = { sum: 0, count: 0 }) { result.sum += value; result.count++; for(const child of children) average(child, result); return result.sum / result.count; }