Generate two output strings depending upon occurrence of character in input string . | javascript program to print two strings made of character occurring once and multiple times ; function to print two strings generated from single string one with characters occurring onces other with character occurring multiple of times ; initialize hashtable with zero entry ; perform hashing for input string ; generate string ( str1 ) consisting char occurring once and string ( str2 ) consisting char occurring multiple times ; print both strings ; driver program
var MAX_CHAR = 256 ; function printDuo ( str ) { var countChar = Array ( MAX_CHAR ) . fill ( 0 ) ; var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) countChar [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; var str1 = " " , str2 = " " ; for ( var i = 0 ; i < MAX_CHAR ; i ++ ) { if ( countChar [ i ] > 1 ) str2 = str2 + String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; else if ( countChar [ i ] == 1 ) str1 = str1 + String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; } document . write ( " " + " " ) ; document . write ( str1 + " " ) ; document . write ( " " + " " ) ; document . write ( str2 + " " ) ; } var str = " " ; printDuo ( str ) ;