Check whether two strings contain same characters in same order | Javascript implementation of the approach ; string class has a constructor that allows us to specify size of string as first parameter and character to be filled in given size as second parameter . ; Function that returns true if the given strings contain same characters in same order ; Get the first character of both strings ; Now if there are adjacent similar character remove that character from s1 ; Now if there are adjacent similar character remove that character from s2 ; If both the strings are equal then return true ; Driver code
function getString ( x ) { return x } function solve ( s1 , s2 ) { var a = getString ( s1 [ 0 ] ) , b = getString ( s2 [ 0 ] ) ; for ( var i = 1 ; i < s1 . length ; i ++ ) if ( s1 [ i ] != s1 [ i - 1 ] ) { a += getString ( s1 [ i ] ) ; } for ( var i = 1 ; i < s2 . length ; i ++ ) if ( s2 [ i ] != s2 [ i - 1 ] ) { b += getString ( s2 [ i ] ) ; } if ( a == b ) return true ; return false ; } var s1 = " " , s2 = " " ; if ( solve ( s1 , s2 ) ) document . write ( " " ) ; else document . write ( " " ) ;