Skip to content

Instantly share code, notes, and snippets.

@nikonov91-dev
Created November 24, 2017 16:32
Show Gist options
  • Save nikonov91-dev/a7b309d69ea26aefc67c153445e7f720 to your computer and use it in GitHub Desktop.
Save nikonov91-dev/a7b309d69ea26aefc67c153445e7f720 to your computer and use it in GitHub Desktop.
practice in creating cocktail sorting
<script>
var num = [10, 100, 2, 0, 10, 50];
var text = "<ul>" + num;
var startAgain = false;
var temp;
for ( i = 0, i < num.lenght, i++ ){
for ( j = 0, j < num.lenght-1-i, j++){
do
if ( num[j] > num[j+1]){
startAgain = true;
temp = num[j];
num[j] = num[j+1];
num[j+1] = temp;
}
text += "</ul>";
document.getElementById("demo").innerHTML = text + "<br>" + num;
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment