KDTree implemented in JavaScript