Insertion Sort

Run Settings
LanguageJavaScript
Language Version
Run Command
const arr=[5,4,2,3,1]; function insertionSort(array){ const length=array.length; for(let i=1;i<length;i++){ let key=array[i]; let j=i; while(j>=1 && array[j-1]>key){ array[j]=array[j-1]; j--; } array[j]=key; } return array; } insertionSort(arr); console.log(arr);
Editor Settings
Theme
Key bindings
Full width
Lines