-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.html
More file actions
36 lines (35 loc) · 1.08 KB
/
sort.html
File metadata and controls
36 lines (35 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Tools - Sort</title>
<script src="components/sidebar-component.js"></script>
<script src="components/header-component.js"></script>
<link href="index.css" rel="stylesheet">
</head>
<body>
<header-component></header-component>
<sidebar-component></sidebar-component>
<main>
<textarea id="content"></textarea>
<button onclick="sort()">Sort</button>
<select id="sort-direction" title="direction">
<option value="asc">Ascending</option>
<option value="desc">Descending</option>
</select>
<code id="output"></code>
</main>
<script>
function sort() {
const content = document.getElementById('content').value.split('\n').filter((v) => v);
console.log('content', content);
const sortDirection = document.getElementById('sort-direction').value;
const sortedContent = content.sort();
if (sortDirection === 'desc') {
sortedContent.reverse();
}
document.getElementById('output').innerHTML = sortedContent.join('<br>');
}
</script>
</body>
</html>