Created
September 29, 2018 12:31
-
-
Save Luke-Rogerson/768be5feb0d3be3922faed93e268aba9 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
// 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