Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Src #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -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.


63 changes: 0 additions & 63 deletions script.js

This file was deleted.

9 changes: 7 additions & 2 deletions index.html → src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
<head>
<meta charset="utf-8" />
<title>Sorting</title>
<script type "text/javascript" src="script.js" async></script>

<link rel="stylesheet" href="style.css" type=text/css>
<link href="https://fonts.googleapis.com/css?family=Indie+Flower" rel="stylesheet">
</head>
<body>
<div id="all">
<div id="Header"> Sorter version 1</div>
<div id="Header"> Sorter version 2</div>
<div id="List"></div>
<div id="Menu">
<label for="textArea">Enter a few words (Separate the words with a comma)</label>
<textarea id="textArea" rows="10" cols="18"> A area for your words. </textarea>

<input type="button" id=IT value="Sort in turn" onclick="sortInTurn()"><br>
<input type="button" id=AZ value="Sort A to Z" onclick="sortAZ()"><br>
<input type="button" id=LText value="Sort by text length" onclick="sortLtext()"><br>
<input type="button" id=RD value="Sort random" onclick="Random()"> <br>
<input type="button" id=Test value="test" onclick="test()"> <br>
</div>
<div style="clear: both"></div>
<div id="footer"></div>

</div>
<script type="text/javascript" src="script.js" async></script>
</body>
</html>
65 changes: 65 additions & 0 deletions src/script.js
Original file line number Diff line number Diff line change
@@ -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("<br>");
}

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("<br>");
}

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("<br>");
}

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("<br>");
}

/*function test (){
//alert (takeWords());
alert (Words[4].trim());

}*/
13 changes: 13 additions & 0 deletions style.css → src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}