Skip to content

Instantly share code, notes, and snippets.

@AleksandrChukhray
Created September 16, 2020 12:34
Show Gist options
  • Select an option

  • Save AleksandrChukhray/f529959fc065b233af26e27473255093 to your computer and use it in GitHub Desktop.

Select an option

Save AleksandrChukhray/f529959fc065b233af26e27473255093 to your computer and use it in GitHub Desktop.
insertion sort algorithm
function insertionSort(arr){
for(let i=1; i < arr.length; i++){
let key = arr[i];
let j = i - 1;
while (j >= 0 && arr[j] > key){
arr[j+1] = arr[j];
j--;
}
arr[j+1] = key;
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment