Check if frequency of character in one string is a factor or multiple of frequency of same character in other string | Function that checks if the frequency of character are a factor or multiple of each other ; map store frequency of each character ; if any frequency is 0 , then continue as condition is satisfied ; if factor or multiple , then condition satisfied ; if condition not satisfied ; Driver code
function multipleOrFactor ( s1 , s2 ) { let m1 = new Map ( ) ; let m2 = new Map ( ) ; for ( let i = 0 ; i < s1 . length ; i ++ ) { if ( m1 [ s1 [ i ] ] ) m1 [ s1 [ i ] ] ++ ; else m1 [ s1 [ i ] ] = 1 } for ( let i = 0 ; i < s2 . length ; i ++ ) { if ( m2 [ s2 [ i ] ] ) m2 [ s2 [ i ] ] ++ ; else m2 [ s2 [ i ] ] = 1 } for ( var it in m1 ) { if ( ! ( m2 [ it ] ) ) continue ; if ( m2 [ it ] % m1 [ it ] == 0 m1 [ it ] % m2 [ it ] == 0 ) continue ; else return false ; } return true ; } let s1 = " " ; let s2 = " " ; multipleOrFactor ( s1 , s2 ) ? document . write ( " " ) : document . write ( " " ) ;