Skip to content

Instantly share code, notes, and snippets.

@carjug
Created March 3, 2015 23:06
Show Gist options
  • Save carjug/6008c4452272f4b3ab6f to your computer and use it in GitHub Desktop.
Save carjug/6008c4452272f4b3ab6f to your computer and use it in GitHub Desktop.
Sort Algorithm js and HTML files
<!doctype HTML>
<head>
<title>
<link rel="stylesheet" type="text/css" href="">
</title>
</head>
<body>
<main>
<ul id="list">
</ul>
<button type="button" id="sort">SORT</button>
</main>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="sortAlgorithm.js"></script>
</body>
function number() {
this.number = Math.floor(Math.random() * 100);
console.log(this.number);
this.toHTML = function(){
return "<li class='value'>" + this.number + "</li>";
}
}
for(var i = 0; i < 20; i++) {
var n = new number();
$('#list').append(n.toHTML());
};
$("#sort").on("click", function () {
for(var i = 0; i < 20; i++){
var first = 0
var last = 0
var k = 0
for(var j = 0; j < 20; j++){
k = j+1;
first = parseInt($(".value:eq("+j+")").text());
last = parseInt($(".value:eq("+k+")").text());
if(first > last) {
$(".value:eq("+j+")").insertAfter($(".value:eq("+k+")"));
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment