Count number of substrings with numeric value greater than X | Function that counts valid sub - strings ; Only take those numbers that do not start with '0' . ; converting the sub - string starting from index ' i ' and having length ' len ' to int and checking if it is greater than X or not ; Driver code
function count ( S , X ) { var count = 0 ; var N = S . length ; for ( var i = 0 ; i < N ; ++ i ) { if ( S [ i ] != ' ' ) { for ( var len = 1 ; ( i + len ) <= N ; ++ len ) { if ( parseInt ( S . substring ( i , i + len ) ) > X ) count ++ ; } } } return count ; } var S = " " ; var X = 97 ; document . write ( count ( S , X ) ) ;