Binary Heap implementation in Javascript