diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..f1750ad --- /dev/null +++ b/Readme.md @@ -0,0 +1,14 @@ +# Sorter version 2 + +This is simple project with sorting data: alphabetically, with length text and randomly, with data input from user. + +## Installation + +https://brq1.github.io/Sorter/ + +## Usage + +Enter a data in textarea. Text must be split of coma ( , ). +Next you select function to sort. + + diff --git a/script.js b/script.js deleted file mode 100644 index 409e567..0000000 --- a/script.js +++ /dev/null @@ -1,63 +0,0 @@ -var Months = [ - "January", - "February", - "March", - "April", - "May", - "Juni", - "July", - "August", - "September", - "Oktober", - "November", - "December" -]; -var MonthsClone = Months.slice(0); - -function sortInTurn(){ - - document.getElementById("List").innerHTML = MonthsClone.join("
"); -} - -function sortAZ(){ - Months.sort(); - if (document.getElementById("AZ").value == "Sort A to Z") { - document.getElementById("AZ").value = "Sort Z to A"; - document.getElementById("List").innerHTML = Months.join("
"); - } - else{ - Months.reverse(); - document.getElementById("AZ").value = "Sort A to Z"; - document.getElementById("List").innerHTML = Months.join("
"); - } -} - -function sortLtext(){ - - var MlenghtText = []; - var temp; - for (var i=0; i < Months.length; i++){ - - - for (var j=1; j < Months.length; j++){ - if (Months[j-1].length > Months[j].length){ - temp = Months[j]; - Months[j] = Months[j-1]; - Months[j-1] = temp; - } - } - } - document.getElementById("List").innerHTML = Months.join("
"); -} - -function Random(){ - var n = Months.length, temp, x; - for (i=0; i < n; i++ ) { - x = Math.floor(Math.random()*n); - temp = Months [i]; - Months[i] = Months[x]; - Months[x] = temp; - } - - document.getElementById("List").innerHTML = Months.join("
"); -} diff --git a/index.html b/src/index.html similarity index 67% rename from index.html rename to src/index.html index d85bcdd..22eb29a 100644 --- a/index.html +++ b/src/index.html @@ -4,23 +4,28 @@ Sorting - +
- +
+ \ No newline at end of file diff --git a/src/script.js b/src/script.js new file mode 100644 index 0000000..9566501 --- /dev/null +++ b/src/script.js @@ -0,0 +1,65 @@ +var azEl = document.getElementById("AZ"); +var listEl = document.getElementById("List"); + +function takeWords(){ + var StringText = document.getElementById("textArea").value; + Words = StringText.split(","); + for (i=0 ; i< Words.length; i++){ + Words[i].trim(); + } + //Words.trim(); +} + +function sortInTurn(){ + takeWords(); + listEl.innerHTML = Words.join("
"); +} + +function sortAZ(){ + takeWords(); + + Words.sort(); + + if (azEl.value == "Sort A to Z") { + azEl.value = "Sort Z to A"; + } else { + Words.reverse(); + azEl.value = "Sort A to Z"; + } + listEl.innerHTML = Words.join("
"); +} + +function sortLtext(){ + takeWords(); + var temp; + for (var i=0; i < Words.length; i++){ + + for (var j=1; j < Words.length; j++){ + if (Words[j-1].length > Words[j].length){ + temp = Words[j]; + Words[j] = Words[j-1]; + Words[j-1] = temp; + } + } + } + listEl.innerHTML = Words.join("
"); +} + +function Random(){ + takeWords(); + var n = Words.length, temp, x; + for (i=0; i < n; i++ ) { + x = Math.floor(Math.random()*n); + temp = Words [i]; + Words[i] = Words[x]; + Words[x] = temp; + } + + listEl.innerHTML = Words.join("
"); +} + +/*function test (){ + //alert (takeWords()); + alert (Words[4].trim()); + +}*/ \ No newline at end of file diff --git a/style.css b/src/style.css similarity index 71% rename from style.css rename to src/style.css index c6fc582..b860fa9 100644 --- a/style.css +++ b/src/style.css @@ -36,4 +36,17 @@ font-family: 'Indie Flower', cursive; padding: 10px; float: right; +} + +#textarea { + padding: 5px; + line-height: 1.5; + border-radius: 10px; + border: 2px solid #fff; + box-shadow: 2px 2px 2px #999; +} + +.label { + display: block; + margin-bottom: 10px; } \ No newline at end of file