Check if two strings are permutation of each other | Function to check whether two strings are Permutation of each other ; Get lengths of both strings ; If length of both strings is not same , then they cannot be Permutation ; Sort both strings ; Compare sorted strings ; Driver Code
function arePermutation ( str1 , str2 ) { let n1 = str1 . length ; let n2 = str2 . length ; if ( n1 != n2 ) return false ; let ch1 = str1 . split ( ' ' ) ; let ch2 = str2 . split ( ' ' ) ; ch1 . sort ( ) ; ch2 . sort ( ) ; for ( let i = 0 ; i < n1 ; i ++ ) if ( ch1 [ i ] != ch2 [ i ] ) return false ; return true ; } let str1 = " " ; let str2 = " " ; if ( arePermutation ( str1 , str2 ) ) document . write ( " " ) ; else document . write ( " " ) ;