Min-max heap done in JavaScript.