Insertion sort

Run Settings
LanguageJavaScript
Language Version
Run Command
function insertionSort(arr){ for(let i=1; i<arr.length; i++){ let element=i; while(arr[element-1]>arr[element]){ let temp = arr[element-1]; arr[element-1]=arr[element]; arr[element]=temp; element--; } console.log(arr) } return arr } console.log(insertionSort([3,2,0,8,5,6,9,4,7,1]));
Editor Settings
Theme
Key bindings
Full width
Lines