Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onlyOne(input1, input2, input3){
- output = false;
- let truthy = 0;
- let falsey = 0;
- if (!!input1) {
- truthy++;
- } else falsey++;
- if (!!input2) {
- truthy++;
- } else falsey++;
- if (!!input3) {
- truthy++;
- } else falsey++;
- if (falsey > truthy) {
- output = true;
- }
- if (falsey > 2) {
- output = false;
- }
- return output;
- }
- function onlyOne(input1, input2, input3){
- if(input1 && !input2 && !input3) return true;
- if(!input1 && input2 && !input3) return true;
- if(!input1 && !input2 && input3) return true;
- return false;
- }
- function onlyOne(input1, input2, input3){
- if(input1 || input2 || input3) {
- if(!input2 && !input3) return true;
- if(!input1 && !input3) return true;
- if(!input1 && !input2) return true;
- }
- return false;
- }
- const xor = (a, b) => !a ^ !b;
- const onlyOne = (a, b, c) => xor(xor(xor(a, b), c), a && b && c)
- function onlyOne(a, b, c){
- if (a) {
- // a is true
- if (b) {
- // a and b are true
- return false;
- }
- // a is true b is false
- return c ? false : true;
- }
- // a is false
- if (b) {
- // a is false, b is true
- return c ? false : true;
- }
- // a and b are false
- return c ? true : false;
- }
- function onlyOne(a, b, c){
- if (a) { return b ? false : c ? false : true }
- return b ? (c ? false : true) : (c ? true : false);
- }
- const table = [false,true,true,false,true,false,false,false];
- function onlyOne(a,b,c){
- return table[(a ? 1 : 0) + (b ? 2 : 0) + (c ? 4 : 0)];
- }
- const onlyOne = (a, b, c) => (!!a ^ !!b ^ !!c) ^ (a && b && c);
Add Comment
Please, Sign In to add comment