-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (28 loc) · 718 Bytes
/
script.js
File metadata and controls
40 lines (28 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$('#description').hide();
var Thing = function() {
this.type = Math.floor(Math.random() * 10);
$('#things').append('<li>'+ this.type + '</li>');
};
var makeThing = function() {
new Thing();
};
$('#create').on('click', makeThing);
var sort = function() {
$('#description').show('slow');
var i = 0;
var interval = setInterval(loop, 1000);
function loop() {
$('li').each(function() {
if(Number($(this).text()) < Number($(this).prev().text())) {
$('li').removeClass('swap');
$(this).addClass('swap');
$(this).insertBefore($(this).prev())
}
})
i++;
if (i == $('li').length) {
clearInterval(interval);
}
}
}
$('#sort').on('click', sort);