Insertion Sort

Run Settings
LanguageJavaScript
Language Version
Run Command
// let array = [8, 5, 2, 9, 10, 1]; let array = [99,44,6,2,1,5,63,87,283,4,0]; function insertionSort(arr) { // debugger; for (let i=1; i<arr.length;i++) { let temp = arr[i]; let j = i-1; while ((arr[j] > temp) && (j >= 0)) { arr[j+1] = arr[j]; j--; } arr[j+1] = temp; } return arr; } insertionSort(array); console.log(array);
Editor Settings
Theme
Key bindings
Full width
Lines