Skip to content

Instantly share code, notes, and snippets.

@ibrahimBanat
Created June 20, 2021 22:32
Show Gist options
  • Save ibrahimBanat/51a15e719119d6dbce33832be7ff8741 to your computer and use it in GitHub Desktop.
Save ibrahimBanat/51a15e719119d6dbce33832be7ff8741 to your computer and use it in GitHub Desktop.
function insertSort(array) {
for (let item = 1; item < array.length; item++) {
for (let index = item; index > 0; index--) {
if (array[index] < array[index - 1]) {
const temp = array[index];
array[index] = array[index - 1];
array[index - 1] = temp;
} else {
break;
}
}
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment