Created
June 13, 2016 16:55
-
-
Save jhgaylor/4591ccc393f8f0bbc315b7fb4b879de7 to your computer and use it in GitHub Desktop.
Does your brain hurt when you think of trees? Mine too... I don't ever want to write this again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countChildren (node) { | |
function _countChildren (node) { | |
if (node.children) { | |
return node.children.map((child) => { | |
return _countChildren(child); | |
}).reduce((memo, next) => { | |
return memo + next; | |
}, 1); | |
} | |
return 1; | |
} | |
return _countChildren(node) - 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment