Skip to content

Instantly share code, notes, and snippets.

@cozzbie
Created January 5, 2020 22:03
Show Gist options
  • Save cozzbie/9570c081b7af53a55085a7187c8900d3 to your computer and use it in GitHub Desktop.
Save cozzbie/9570c081b7af53a55085a7187c8900d3 to your computer and use it in GitHub Desktop.
In-place insert sort.
const insertSort = array => {
for(let i = 1; i < array.length; i++) {
const el = array[i];
let j = i - 1;
while(j >= 0 && el < array[j]){
array[i--] = array[j];
array[j] = el;
j--;
}
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment