Check if given Binary string follows then given condition or not | Function to check if the string follows rules or not ; Check for the first condition ; Check for the third condition ; Check for the second condition ; Given String str ; Function Call
function checkrules ( s ) { if ( s . length == 0 ) return true ; if ( s [ 0 ] != ' ' ) return false ; if ( s . length > 2 ) { if ( s [ 1 ] == ' ' && s [ 2 ] == ' ' ) return checkrules ( s . substring ( 3 ) ) ; } return checkrules ( s . substring ( 1 ) ) ; } var str = " " ; if ( checkrules ( str ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }