Skip to content

Instantly share code, notes, and snippets.

@Luke-Rogerson
Created September 29, 2018 12:31
Show Gist options
  • Save Luke-Rogerson/768be5feb0d3be3922faed93e268aba9 to your computer and use it in GitHub Desktop.
Save Luke-Rogerson/768be5feb0d3be3922faed93e268aba9 to your computer and use it in GitHub Desktop.
InsertionSort created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/InsertionSort
// An implementation of a basic insertion sort.
function insertionSort(arr) {
let temp = [];
for (let i = 1; i < arr.length; i++) {
for (let j = 0; j < i; j++) {
// console.log(arr[j]);
if (arr[i] < arr[j]) {
temp[0] = arr[i];
arr[i] = arr[j];
arr[j] = temp[0];
}
}
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment