Check if two array of string are equal by performing swapping operations | Function to check whether brr [ ] can be made equal to arr [ ] by doing swapping operations ; siz variable to store siz of string ; iterate till N to sort strings ; sort each string in arr [ ] ; sort each string in brr [ ] ; Sort both the vectors so that all the comparable strings will be arranged ; iterate till N to compare string in arr [ ] and brr [ ] ; Compare each string ; Return false becaues if atleast one string is not equal then brr [ ] cannot be converted to arr [ ] ; All the strings are compared so at last return true . ; Driver code ; Store the answer in variable
function checkEqualArrays ( arr , brr , N ) { let siz = arr [ 0 ] . length ; for ( let i = 0 ; i < N ; i ++ ) { arr [ i ] = arr [ i ] . split ( " " ) . sort ( ) . join ( " " ) brr [ i ] = brr [ i ] . split ( " " ) . sort ( ) . join ( " " ) } arr . sort ( ) brr . sort ( ) for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != brr [ i ] ) { return false ; } } return true ; } let N = 2 ; let arr = [ " " , " " ] ; let brr = [ " " , " " ] ; let ans = checkEqualArrays ( arr , brr , N ) ; if ( ans ) document . write ( " " ) ; else document . write ( " " ) ;