kd-tree implementation in JavaScript