From 29347d5be85d3c888b8c0827c174d309286b23ba Mon Sep 17 00:00:00 2001 From: Ilya Tychinin Date: Mon, 29 Oct 2012 16:27:51 +0600 Subject: [PATCH 1/2] dz1 --- dz1.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 dz1.js diff --git a/dz1.js b/dz1.js new file mode 100644 index 0000000..c08c7c9 --- /dev/null +++ b/dz1.js @@ -0,0 +1,30 @@ +/*jslint browser: true*/ +var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + +function sRand() { + 'use strict'; + return Math.random() > 0.5 ? 1 : -1; +} + +function sBubble(arr) { + 'use strict'; + var i, j, tmp; + for (i = 0; i < arr.length - 1; i += 1) { + for (j = 0; j < arr.length - 1; j += 1) { + if (arr[j + 1] < arr[j]) { + tmp = arr[j + 1]; + arr[j + 1] = arr[j]; + arr[j] = tmp; + } + } + } + return arr; +} + +arr.sort(sRand); + +window.onload = (function () { + 'use strict'; + document.getElementById('arr').innerHTML = arr; + document.getElementById('btn').onclick = function () { document.getElementById('sarr').innerHTML = sBubble(arr); }; +}()); \ No newline at end of file From 2fc8fe7ee888ab9f73f5d15679b9a4d5331f1a70 Mon Sep 17 00:00:00 2001 From: Ilya Tychinin Date: Mon, 29 Oct 2012 18:24:18 +0600 Subject: [PATCH 2/2] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dz1.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/dz1.js b/dz1.js index c08c7c9..c0ce997 100644 --- a/dz1.js +++ b/dz1.js @@ -1,30 +1,32 @@ -/*jslint browser: true*/ -var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; +/*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(arr) { +function sBubble(arrayForSort) { 'use strict'; var i, j, tmp; - for (i = 0; i < arr.length - 1; i += 1) { - for (j = 0; j < arr.length - 1; j += 1) { - if (arr[j + 1] < arr[j]) { - tmp = arr[j + 1]; - arr[j + 1] = arr[j]; - arr[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 arr; + return arrayForSort; } -arr.sort(sRand); +arrayForSort.sort(sRand); -window.onload = (function () { +window.addEventListener('load', function () { 'use strict'; - document.getElementById('arr').innerHTML = arr; - document.getElementById('btn').onclick = function () { document.getElementById('sarr').innerHTML = sBubble(arr); }; -}()); \ No newline at end of file + document.getElementById('arrayForSort').innerHTML = arrayForSort; + document.getElementById('sortButton').addEventListener('click', function () { + document.getElementById('sortResult').innerHTML = sBubble(arrayForSort); + }, false); +}, false); \ No newline at end of file