Check whether the string S1 can be made equal to S2 with the given operation | Function to return the string formed by the odd indexed characters of s ; Function to return the string formed by the even indexed characters of s ; Function that returns true if s1 can be made equal to s2 with the given operation ; Get the string formed by the even indexed characters of s1 ; Get the string formed by the even indexed characters of s2 ; Get the string formed by the odd indexed characters of s1 ; Get the string formed by the odd indexed characters of s2 ; Sorting all the lists ; If the strings can be made equal ; Driver Code
function partOdd ( s ) { var st = " " ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( i % 2 !== 0 ) st += s [ i ] ; } return st ; } function partEven ( str ) { var s = " " ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( i % 2 === 0 ) s += str [ i ] ; } return s ; } function canBeMadeEqual ( s1 , s2 ) { var even1 = partEven ( s1 ) . split ( " " ) ; var even2 = partEven ( s2 ) . split ( " " ) ; var odd1 = partOdd ( s1 ) . split ( " " ) ; var odd2 = partOdd ( s2 ) . split ( " " ) ; even1 . sort ( ) ; even2 . sort ( ) ; odd1 . sort ( ) ; odd2 . sort ( ) ; var even_s1 = even1 . join ( " " ) ; var even_s2 = even2 . join ( " " ) ; var odd_s1 = odd1 . join ( " " ) ; var odd_s2 = odd2 . join ( " " ) ; if ( even_s1 === even_s2 && odd_s1 === odd_s2 ) return true ; return false ; } var s1 = " " ; var s2 = " " ; if ( canBeMadeEqual ( s1 , s2 ) ) document . write ( " " ) ; else document . write ( " " ) ;