File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments