html
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
<!DOCTYPE html>
<html>
<head>
<title> Removing duplicate words. </title>
<meta charset="utf-8" />
<style>
</style>
</head>
<body>
<div id="container">
<div id="intro">
Removing duplicate words
</div>
<p id="please"> Please enter your string:
</p>
<input type="text" id="input" />
<button id="butt" onclick="myFunc()"> Check </button>
<button id="clear" onclick="myClear()"> Clear </button>
<div id="output"> Output: </div>
</div>
<script>
</script>
Enter to Rename, Shift+Enter to Preview
css
css
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
body {
font-family: sans-serif;
}
#intro {
border: 1px solid lightgray;
border-radius:5px;
font-weight:bold;
color: darkgreen;
background-color: #bbeedd;
text-align:center;
margin:10px;
}
#container {
border:1px solid lightgray;
border-radius:5px;
background-color: #bbeecc;
}
p {
border:1px solid lightgray;
border-radius:5px;
text-indent:6px;
font-weight:bold;
color: darkgreen;
margin:5px;
text-align:center;
}
Enter to Rename, Shift+Enter to Preview
js
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
function myFunc() {
var a = document.getElementById('input').value;
var b = document.getElementById('output');
a = a.split('');
// console.log('a='+a);
var x = [], d = [];
for(var i=0; i<a.length; i++) {
if(/[^a-zA-Z]/.test(a[i])) {
if( /\w/.test(a[i-1]) ) {
d = d.join('');
x.push(d);
d = [];
}
d.push(a[i]);
}
if(/[a-zA-Z]/.test(a[i])) {
if(/\W/.test(a[i-1])) {
d = d.join('');
x.push(d);
d = [];
}
d.push(a[i]);
}
}
d = d.join('');
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run