Created
December 10, 2015 13:26
-
-
Save ravinsinghd/0ac977e21ce23331b3db 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
var array = [5, 2, 4, 6, 1, 3]; | |
for (j = 0; j <= array.length; j++) | |
{ | |
var key = array[j]; | |
var i = j - 1; | |
while (i >= 0 && array[i] > key) | |
{ | |
array[i + 1] = array[i]; | |
i = i - 1; | |
array[i + 1] = key; | |
} | |
} | |
console.log(array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment