Check whether the frequencies of all the characters in a string are prime or not | function that returns true if n is prime else false ; 1 is not prime ; check if there is any factor or not ; function that returns true if the frequencies of all the characters of s are prime ; create a map to store the frequencies of characters ; update the frequency ; check whether all the frequencies are prime or not ; Driver code ; if all the frequencies are prime
function isPrime ( n ) { var i ; if ( n == 1 ) return false ; for ( i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function check_frequency ( s ) { var m = new Map ( ) ; for ( var i = 0 ; i < s . length ; i ++ ) if ( m . has ( s [ i ] ) ) { m . set ( s [ i ] , m . get ( s [ i ] ) + 1 ) ; } else { m . set ( s [ i ] , 1 ) ; } for ( var ch = ' ' . charCodeAt ( 0 ) ; ch <= ' ' . charCodeAt ( 0 ) ; ch ++ ) if ( m . get ( String . fromCharCode ( ch ) ) > 0 && ! isPrime ( m . get ( String . fromCharCode ( ch ) ) ) ) return false ; return true ; } var s = " " ; if ( check_frequency ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;