Created
May 22, 2019 07:48
-
-
Save Ikhan/e377f28df1afb15368f8d55cb5a16c67 to your computer and use it in GitHub Desktop.
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) { | |
for (let i =1; i < arr.length; i++) { | |
let currentVal = arr[i]; | |
let j; | |
for (j=i-1; j>=0 && arr[j] > currentVal;j--) { | |
arr[j+1] = arr[j]; | |
} | |
arr[j+1] = currentVal; | |
console.log(arr); | |
} | |
return arr; | |
} | |
insertionSort([2,1,9,6,8]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment