From 553f787894a1b806ac032a624aeea0c7e110e667 Mon Sep 17 00:00:00 2001 From: Pavel Khudyakov Date: Thu, 11 Oct 2012 00:51:16 +0600 Subject: [PATCH 1/2] bubble sort --- bubble.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 bubble.js diff --git a/bubble.js b/bubble.js new file mode 100644 index 0000000..50a364a --- /dev/null +++ b/bubble.js @@ -0,0 +1,13 @@ +function bubble() { + "use strict"; + var m = document.forms["form"].elements["unsorted"].value.split(/\s*,\s*/), count, max, i, j; + count = m.length - 1; + for (i = 0; i < count; i++) + for (j = 0; j < count - i; j++) + if (+(m[j]) > +(m[j + 1])) { + max = m[j]; + m[j] = m[j + 1]; + m[j + 1] = max; + } + document.forms["form"].elements["sorted"].value = m.join(", "); +} \ No newline at end of file From 95d3659851f823d1cbe42ca2784a0a73aa82002b Mon Sep 17 00:00:00 2001 From: Pavel Khudyakov Date: Thu, 11 Oct 2012 00:55:34 +0600 Subject: [PATCH 2/2] var fix --- bubble.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bubble.js b/bubble.js index 50a364a..069fcfe 100644 --- a/bubble.js +++ b/bubble.js @@ -1,6 +1,7 @@ function bubble() { "use strict"; - var m = document.forms["form"].elements["unsorted"].value.split(/\s*,\s*/), count, max, i, j; + var m, count, i, j, max; + m = document.forms["form"].elements["unsorted"].value.split(/\s*,\s*/); count = m.length - 1; for (i = 0; i < count; i++) for (j = 0; j < count - i; j++)