Check if all the 1 's in a binary string are equidistant or not | Function that returns true if all the 1 's in the binary string s are equidistant ; Initialize vector to store the position of 1 's ; Store the positions of 1 's ; Size of the position vector ; If condition isn 't satisfied ; Drivers code
function check ( s , l ) { var pos = [ ] ; for ( var i = 0 ; i < l ; i ++ ) { if ( s [ i ] == ' ' ) pos . push ( i ) ; } var t = pos . length ; for ( var i = 1 ; i < t ; i ++ ) { if ( ( pos [ i ] - pos [ i - 1 ] ) != ( pos [ 1 ] - pos [ 0 ] ) ) return false ; } return true ; } var s = " " ; var l = s . length ; if ( check ( s , l ) ) document . write ( " " ) ; else document . write ( " " ) ;