Heap data structure in node.js