Related to my original question, how would you xor three boolean variables in javascript. One variable can be true the rest must be false.
This is my solution, but I feel there is a better one:
function isValid(a, b, c) {
return (a !== b ! == c) && [a, b, c].includes(false);
}
I've gotten some feed back from the comments, let me define what I'm asking (sorry for all the confusion).
I'm actually doing this in a typescript class. I figured I'd just remove the method and make it a classless function. I realize now that this does affect the solution. Sorry about that.
I suppose I must have missused the term XOR. What I'm trying to say is, only a OR b OR c can be true, and one of them must be true. I hope that is more clear.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…