Last active
February 1, 2016 01:48
-
-
Save eakray/a40fdcf5a566f5182885 to your computer and use it in GitHub Desktop.
Tree height function
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
| var getTreeHeight = function(tree) { | |
| var counter = 1; | |
| var max = 0; | |
| var position = tree.root; | |
| (function recurse(node){ | |
| if(!node){ | |
| return; | |
| } | |
| if(counter > max){ | |
| max = counter; | |
| } | |
| recurse(node.left); | |
| recurse(node.right); | |
| counter++; | |
| })(position); | |
| return max; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment