i tried to put this.val[swap] = this.val[index] because it is same as index
what the logic
sink(){
let index= 0;
const length = this.val.length; // total length
const element = this.val[index]
if(swap === null) break;
this.val[index] = this.val[swap];
this.val[swap] = element;
index= swap;
}
}
}