Skip to content

Instantly share code, notes, and snippets.

@ravinsinghd
Created December 10, 2015 13:26
Show Gist options
  • Save ravinsinghd/0ac977e21ce23331b3db to your computer and use it in GitHub Desktop.
Save ravinsinghd/0ac977e21ce23331b3db to your computer and use it in GitHub Desktop.
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