-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubtract.html
67 lines (58 loc) · 1.62 KB
/
subtract.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
<html>
<head>
<title>subtract</title>
<style>
textarea {
width:30%;
height:80%;
}
button#subtractbutton {
width:90%
}
div#content {
width: 100%;
text-align: center
}
</style>
</head>
<body>
<h1>Subtract strings from strings...</h1>
<p>Version 1.0 by René Tronsgaard Rasmussen</p>
<div id="content">
<textarea id="input">list
of
awesome
strings</textarea>
<textarea id="subtract">strings
that
you
want
to
subtract</textarea>
<textarea id="result"></textarea>
<button id="subtractbutton" onClick="subtract()">Subtract!</button>
</div>
<script>
inputfield = document.getElementById("input")
subtractfield = document.getElementById("subtract")
resultfield = document.getElementById("result")
function subtract(){
// Split for every line
inputlines = inputfield.value.split("\n");
subtractlines = subtractfield.value.split("\n");
resultlines = inputlines
// Loop over strings to subtract
for (i=0; i < subtractlines.length; i++){
k = resultlines.indexOf(subtractlines[i])
while (k != -1){
resultlines.splice(k,1)
k = resultlines.indexOf(subtractlines[i])
}
}
resultfield.value = resultlines.join("\n")
}
// Run the script at load for demo purpose
subtract()
</script>
</body>
</html>