Check if the given string is linear or not | Function to check if the given string is linear or not ; Iterate over string ; If character is not same as the first character then return false ; Increment the tmp ; Given String str ; Function call
function is_linear ( s ) { let tmp = 0 ; let first = s [ 0 ] ; for ( let pos = 0 ; pos < s . length ; pos += tmp ) { if ( s [ pos ] != first ) { return false ; } tmp ++ ; } return true ; } let str = " " ; if ( is_linear ( str ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }