function insertionSort(array) { // start with index 1 because only one element is already sorted for(let i=1; i= 0 && array[j] > key) { array[j+1] = array[j]; j--; } array[j+1] = key; } return array; } console.log(insertionSort([4,5,6,7,8,10,1,2,3,4])) // output : [1,2,3,4,4,5,6,7,8,10]