The error is in the insert method of the solution provided.
var MaxHeap = function() {
this.heap = [null];
this.insert = (ele) => {
var index = this.heap.length;
var arr = [...this.heap];
arr.push(ele);
while (ele > arr[Math.floor(index / 2)] && index > 1) {
arr[index] = arr[Math.floor(index / 2)];
arr[Math.floor(index / 2)] = ele;
index = arr[Math.floor(index / 2)]; // (*)
}
this.heap = arr;
}
//....rest of the code
the new index should be the index of the parent element so line (*) should be :
index = Math.floor(index / 2);