Javascript implementation of a binary tree