I've been looking for a way to micro-optimize the following logical expression in Node.js, but I failed to find any better method of implementing it:
Suppose A and B vars, both are booleans (results of complex methods/expressions):
if ( (A && B) || (!A && !B) ) {
return true;
}
return false;
//Obviously the returns are redundant in this case.
The truth table for this expression is:
╔════╦═══════╦═══════╗
║ ║ A ║ !A ║
╠════╬═══════╬═══════╣
║ B ║ true ║ false ║
╠════╬═══════╬═══════╣
║ !B ║ false ║ true ║
╚════╩═══════╩═══════╝
Thanks from ahead!
该表达式等效:
return A === B;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.