Count of substrings of a Binary string containing only 1 s | Function to find the total number of substring having only ones ; Driver Code
function countOfSubstringWithOnlyOnes ( s ) { var res = 0 , count = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { count = s [ i ] == ' ' ? count + 1 : 0 ; res = ( res + count ) ; } return res ; } var s = " " ; document . write ( countOfSubstringWithOnlyOnes ( s ) ) ;