I do not understand what is the reason why this is not working. It works with i=9. But it does not operate with i=10 properly.
function insertionSort(array) {
for(let i=0;i<array.length;i++){
let temp=array[i];
for(let j=10;j>i;j--){
while(array[j]<array[i]){
array[i]=array[j]
array[j]=temp
}
}
}
console.log(array)
}
insertionSort([7,1,5,4,2,1,11,10,9,5643,1,75]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36
.
Challenge: Implement Insertion Sort
Link to the challenge: