Skip to content

Instantly share code, notes, and snippets.

@Luke-Rogerson
Created September 29, 2018 12:30
Show Gist options
  • Save Luke-Rogerson/d8452e29ff872d71fae365504c8e9804 to your computer and use it in GitHub Desktop.
Save Luke-Rogerson/d8452e29ff872d71fae365504c8e9804 to your computer and use it in GitHub Desktop.
InsertionSort created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/InsertionSort
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];
console.log(arr);
console.log('TEMP: ', temp)
}
}
}
return arr;
}
insertionSort([3, 14, 14, 15, 19, 3, 6, 10, 8, 14]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment