Skip to content
Open

dz1 #15

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions dz1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*jslint browser: true*/
var arrayForSort = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

function sRand() {
'use strict';
return Math.random() > 0.5 ? 1 : -1;
}

function sBubble(arrayForSort) {
'use strict';
var i, j, tmp;
for (i = 0; i < arrayForSort.length - 1; i += 1) {
for (j = 0; j < arrayForSort.length - 1; j += 1) {
if (arrayForSort[j + 1] < arrayForSort[j]) {
tmp = arrayForSort[j + 1];
arrayForSort[j + 1] = arrayForSort[j];
arrayForSort[j] = tmp;
}
}
}
return arrayForSort;
}

arrayForSort.sort(sRand);

window.addEventListener('load', function () {
'use strict';
document.getElementById('arrayForSort').innerHTML = arrayForSort;
document.getElementById('sortButton').addEventListener('click', function () {
document.getElementById('sortResult').innerHTML = sBubble(arrayForSort);
}, false);
}, false);