Print all distinct characters of a string in order ( 3 Methods ) | Javascript program to print distinct characters of a string . ; Print duplicates present in the passed string ; Create an array of size 256 and count of every character in it ; Count array with frequency of characters ; Print characters having count more than 0 ; Driver program
let NO_OF_CHARS = 256 ; function printDistinct ( str ) { let count = new Array ( NO_OF_CHARS ) ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) { count [ i ] = 0 ; } let i ; for ( i = 0 ; i < str . length ; i ++ ) if ( str [ i ] != ' ' ) count [ str [ i ] . charCodeAt ( 0 ) ] ++ ; let n = i ; for ( i = 0 ; i < n ; i ++ ) if ( count [ str [ i ] . charCodeAt ( 0 ) ] == 1 ) document . write ( str [ i ] ) ; } let str = " " ; printDistinct ( str ) ;