Created
September 29, 2018 12:30
-
-
Save Luke-Rogerson/d8452e29ff872d71fae365504c8e9804 to your computer and use it in GitHub Desktop.
InsertionSort created by Luke_Rogerson - https://repl.it/@Luke_Rogerson/InsertionSort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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