Check if given string contains all the digits | JavaScript implementation of the approach ; Function that returns true if ch is a digit ; Function that returns true if str contains all the digits from 0 to 9 ; To mark the present digits ; For every character of the String ; If the current character is a digit ; Mark the current digit as present ; For every digit from 0 to 9 ; If the current digit is not present in str ; Driver code
let MAX = 10 ; function isDigit ( ch ) { if ( ch >= ' ' && ch <= ' ' ) return true ; return false ; } function allDigits ( str , len ) { let present = Array . from ( { length : MAX } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < len ; i ++ ) { if ( isDigit ( str [ i ] ) ) { let digit = str [ i ] - ' ' ; present [ digit ] = true ; } } for ( let i = 0 ; i < MAX ; i ++ ) { if ( ! present [ i ] ) return false ; } return true ; } let str = " " ; let len = str . length ; if ( allDigits ( str , len ) ) document . write ( " " ) ; else document . write ( " " ) ;