Skip to content

Instantly share code, notes, and snippets.

@Ikhan
Created May 22, 2019 07:48
Show Gist options
  • Save Ikhan/e377f28df1afb15368f8d55cb5a16c67 to your computer and use it in GitHub Desktop.
Save Ikhan/e377f28df1afb15368f8d55cb5a16c67 to your computer and use it in GitHub Desktop.
function insertionSort(arr) {
for (let i =1; i < arr.length; i++) {
let currentVal = arr[i];
let j;
for (j=i-1; j>=0 && arr[j] > currentVal;j--) {
arr[j+1] = arr[j];
}
arr[j+1] = currentVal;
console.log(arr);
}
return arr;
}
insertionSort([2,1,9,6,8]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment