Skip to content

Commit a4bda04

Browse files
committed
Added code for String-Remove Duplicates
1 parent a292255 commit a4bda04

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Strings/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--Author: Jayanth Kumar Tumuluri-->
2+
3+
<!DOCTYPE html>
4+
<html lang="en">
5+
6+
<head>
7+
<meta charset="utf-8">
8+
<title>String Operations</title>
9+
<script src="script.js"></script>
10+
</head>
11+
12+
<body>
13+
<label for="stringinp">Input</label>
14+
<input type="text" id="stringinp" name="input"><br>
15+
<button id="submit" onclick="removeDuplicates()">Remove Consecutive Duplicates</button>
16+
<p id="result"></p>
17+
</body>
18+
19+
</html>

Strings/script.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*Author: Jayanth Kumar Tumuluri
2+
Github: Jayanth20
3+
*/
4+
function removeDuplicates() {
5+
var str = document.getElementById("stringinp").value;
6+
var n = str.length;
7+
if (n <= 1 || n > 1000) {
8+
alert('Please enter a valid string');
9+
} else {
10+
let j = "";
11+
let r = "";
12+
for (var i = 0; i < n; i++) {
13+
let chars = str.charAt(i);
14+
if (chars !== j) {
15+
r += chars;
16+
j = chars;
17+
}
18+
}
19+
document.getElementById('result').innerHTML = "Result after removal: " + r;
20+
console.log(r);
21+
}
22+
}

0 commit comments

Comments
 (0)