Distinct state codes that appear in a string as contiguous sub | Function to return the count of distinct state codes ; Insert every sub - string of length 2 in the set ; Return the size of the set ; Driver code
function countDistinctCode ( str ) { var codes = new Set ( ) ; for ( var i = 0 ; i < str . length - 1 ; i ++ ) codes . add ( str . substr ( i , 2 ) ) ; return codes . size ; } var str = " " ; document . write ( countDistinctCode ( str ) )