let Array = [31, 41, 59, 26, 41, 58]
let len = Array.length;
for (let j=1; j < len; j++) {
let key = Array[j]
console.log(key)
let i = j-1
while(i > 0 && Array[i] > key) {
Array[i+1] = Array[i]
i = i-1
}
Array[i+1] = key
}
console.log(Array)
Output: [ 31, 26, 41, 41, 58, 59 ]
Why the result doesn't correct? I didn't know what the problem here. Can anyone help me?