Evaluate a boolean expression represented as string | Evaluates boolean expression and returns the result ; Traverse all operands by jumping a character after every iteration . ; If operator next to current operand is AND . ; If operator next to current operand is OR . ; If operator next to current operand is XOR ( Assuming a valid input ) ; Driver code
function evaluateBoolExpr ( s ) { let n = s . length ; for ( let i = 0 ; i < n ; i += 2 ) { if ( i + 1 < n && i + 2 < n ) { if ( s [ i + 1 ] == ' ' ) { if ( s [ i + 2 ] == ' ' s [ i ] == 0 ) { s [ i + 2 ] = ' ' ; } else { s [ i + 2 ] = ' ' ; } } else if ( ( i + 1 ) < n && s [ i + 1 ] == ' ' ) { if ( s [ i + 2 ] == ' ' s [ i ] == ' ' ) { s [ i + 2 ] = ' ' ; } else { s [ i + 2 ] = ' ' ; } } else { if ( s [ i + 2 ] == s [ i ] ) { s [ i + 2 ] = ' ' ; } else { s [ i + 2 ] = ' ' ; } } } } return ( s [ n - 1 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; } let s = " " ; let sb = s . split ( ' ' ) ; document . write ( evaluateBoolExpr ( sb ) + " " ) ;