export let heapify = (arr) => {
const swapDown = (arr, n, i) => {
let largest = i;
const left = 2 * i + 1;
const right = 2 * i + 2;
if (left < n && arr[left] > arr[largest]) {
largest = left;
}
if (left < n && arr[right] > arr[largest]) {
largest = right;
}
if (largest !== i) {
[arr[i], arr[largest]] = [arr[largest], arr[i]];
swapDown(arr, n, largest);
}
};
for (let i = Math.floor(arr.length / 2 - 1); i >= 0; i--) {
swapDown(arr, arr.length, i);
}
return arr;
};