-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
89 lines (77 loc) · 2.11 KB
/
index.html
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>gameOfLife-Convertor</title>
</head>
<body>
<textarea name="" id="input" cols="30" rows="10"></textarea>
<button id="convert" >convert</button>
<label for="">Run Length Encoded</label><input type="checkbox" name="erge" id="ex">
<textarea name="" id="output" cols="30" rows="10"></textarea>
</body>
<script>
let input = document.getElementById("input");
let output = document.getElementById("output");
let ex = document.getElementById("ex");
let button = document.getElementById("convert");
button.addEventListener("click", () => {
let text = ''
if (ex.checked) {
let inp = input.value.replace(/\n/gi, '');
let nb = 1;
let n = true;
for (let i = 0; i < inp.length; i++) {
switch (inp[i]) {
case 'b':
text += genrate_string('.', nb);
nb = 1;
n = true;
break;
case 'o':
text += genrate_string('O', nb);
nb = 1;
n = true;
break;
case '$':
nb = 1;
n = true;
text += '\n';
break;
default:
let v = parseInt(inp[i], 10)
nb = n? v : nb*10+ v;
n = false;
break;
}
}
text = text.split('\n');
} else {
text = input.value.split('\n');
}
for (let i = 0; i < text.length; i++) {
text[i] = text[i].split('');
for (let j = 0; j < text[i].length; j++) {
text[i][j] = text[i][j] == '.'? 1 : 0;
}
}
fillEnd(text[text.length-1], text[text.length-2].length)
function genrate_string (str, n) {
let out = '';
for (let i = 0; i < n; i++) {
out += str;
}
return out;
}
function fillEnd (str, l) {
let out = '';
while (str.length < l) {
str.push(0)
}
}
output.value =JSON.stringify(text).replace(/,/gi, ';');
})
</script>
</html>