Javascript Clean Solution
\nvar averageOfSubtree = function (root) {\n    let ans = 0;\n    function dfs(node) {\n        if (node === null) return [0, 0];\n        let [leftSum, leftCou
```\nvar averageOfSubtree = function (root) {\n    let ans = 0;\n    function dfs(node) {\n        if (node === null) return [0, 0];\n        let [leftSum, leftCount] = dfs(node.left);\n        let [rightSum, rightCount] = dfs(node.right);\n\n        let sum = leftSum + rightSum + node.val;\n        let count = leftCount + rightCount + 1;\n        if (Math.floor(sum / count) === node.val) ans++;\n        return [sum, count];\n    }\n\n    dfs(root);\n\n    return ans;\n};\n```
['Depth-First Search', 'JavaScript']