-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.js
75 lines (68 loc) · 2.41 KB
/
sort.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function sort() {
var sort_col = document.getElementById("sortcol");
insep = document.getElementById("insep");
sortarray = sort_col.value.split(insep.value.replace(/\\n/g, "\n").replace(/\\t/g, "\t"));
outsep = document.getElementById("outsep");
sort_col.value = sortarray.sort().join(outsep.value).replace(/\\n/g, "\n").replace(/\\t/g, "\t");
}
function uniq() {
var sort_col = document.getElementById("sortcol");
insep = document.getElementById("insep");
outsep = document.getElementById("outsep");
uniqarray = sort_col.value.split(insep.value.replace(/\\n/g, "\n").replace(/\\t/g, "\t"));
sort_col.value = unique(uniqarray).join(outsep.value).replace(/\\n/g, "\n").replace(/\\t/g, "\t");
}
function unique(a) {
u = new Array(0);
for(i=0;i<a.length;i++){
if(!contains(u, a[i])){
u.length+=1;
u[u.length-1]=a[i];
}
}
return u;
}
function contains(a, e) {
for(j=0;j<a.length;j++)if(a[j]==e)return true;
return false;
}
function uniqd() {
var sort_col = document.getElementById("sortcol");
insep = document.getElementById("insep");
outsep = document.getElementById("outsep");
uniqarray = sort_col.value.split(insep.value.replace(/\\n/g, "\n").replace(/\\t/g, "\t"));
sort_col.value = uniqued(uniqarray).join(outsep.value).replace(/\\n/g, "\n").replace(/\\t/g, "\t");
}
function uniqued(a) {
uniq1 = new Array(0);
uniq2 = new Array(0);
for(i=0;i<a.length;i++){
if(!contains(uniq1, a[i])){
uniq1.length+=1;
uniq1[uniq1.length-1]=a[i];
} else {
uniq2.length+=1;
uniq2[uniq2.length-1]=a[i];
}
}
return uniq2;
}
function random() {
var sort_col = document.getElementById("sortcol");
var insep = document.getElementById("insep");
var a = sort_col.value.split(insep.value.replace(/\\n/g, "\n").replace(/\\t/g, "\t"));
var outsep = document.getElementById("outsep");
var b = new Array(0);
for (item in a) {
b.push(Math.random() + "@@" + a[item]);
}
c = b.sort().join(outsep.value).replace(/\\n/g, "\n").replace(/\\t/g, "\t").replace(/0\.[\d]+@@/g, "");
sort_col.value = c;
}
function reverse() {
var sort_col = document.getElementById("sortcol");
insep = document.getElementById("insep");
sortarray = sort_col.value.split(insep.value.replace(/\\n/g, "\n").replace(/\\t/g, "\t"));
outsep = document.getElementById("outsep");
sort_col.value = sortarray.reverse().join(outsep.value).replace(/\\n/g, "\n").replace(/\\t/g, "\t");
}