Check whether a given string is Heterogram or not | Javascript program to check whether the given string is Heterogram or not . ; Traversing the string . ; Ignore the space ; If already encountered ; Else return false . ; Driver code
function isHeterogram ( s , n ) { var hash = Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( s [ i ] != ' ' ) { if ( hash [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] == 0 ) hash [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = 1 ; else return false ; } } return true ; } var s = " " ; var n = s . length ; ( isHeterogram ( s , n ) ) ? ( document . write ( " " ) ) : ( document . write ( " " ) ) ;