param { string } str return { number } function CountBinarySubstrings ( str ) { let r = [ ] ; let match = ( str ) : string => { let j = str . match ( /^(0+|1+)/ ) [ 0 ] ; let o = ( parseInt ( j [ 0 ] ) ^ 1 ) . toString ( ) . repeat ( j . length ) ; let reg = new RegExp ( `^(${ j }${ o })` ) ; if ( reg . test ( str ) ) { return RegExp . $1 ; } else { return '' ; } } ; for ( let i = 0 , len = str . length - 1 ; i < len ; i ++ ) { let sub = match ( str . slice ( i ) ) ; if ( sub ) { r . push ( sub ) ; } } return r . length ; } export { CountBinarySubstrings } ;