布尔对立面 [英] boolean opposites

查看:94
本文介绍了布尔对立面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法写这个更简单?

函数makeOpposite(a){

if(!a){

a = true ;

}

else {

a = false;

}

}

解决方案

windandwaves写道:


有没有办法写这个更简单?


函数makeOpposite(a){

if(!a){

a = true;

}

else {

a = false;

}

}


a =!a;


-

Ian Collins。


2月15日下午2:33,Ian Collins< ian-n ... @ hotmail.comwrote:


windandwaves写道:


有没有办法写这个更简单?


function makeOpposite(a){

if(!a){

a = true ;

}

else {

a = false;

}

}



a =!a;


-

Ian Collins。



真棒!谢谢Ian ...


windandwaves写道:


2月15日,2:33下午,Ian Collins< ian-n ... @ hotmail.comwrote:


> windandwaves写道:


>>有没有办法写这个更简单?
函数makeOpposite(a){
if(!a){
a = true;
}
其他{
a = false;
}
}


a =!a;



或:


a ^ = true;


-

John W. Kennedy

Logres的盲人统治者

以理性美德的谬误滋养土地。 br $> b $ b - 查尔斯威廉姆斯。 Taliessin通过Logres:Prelude


Is there a way to write this simpler?
function makeOpposite(a) {
if(!a) {
a = true;
}
else {
a = false;
}
}

解决方案

windandwaves wrote:

Is there a way to write this simpler?
function makeOpposite(a) {
if(!a) {
a = true;
}
else {
a = false;
}
}

a = !a;

--
Ian Collins.


On Feb 15, 2:33 pm, Ian Collins <ian-n...@hotmail.comwrote:

windandwaves wrote:

Is there a way to write this simpler?

function makeOpposite(a) {
if(!a) {
a = true;
}
else {
a = false;
}
}


a = !a;

--
Ian Collins.

awesome! Thanks Ian...


windandwaves wrote:

On Feb 15, 2:33 pm, Ian Collins <ian-n...@hotmail.comwrote:

>windandwaves wrote:

>>Is there a way to write this simpler?
function makeOpposite(a) {
if(!a) {
a = true;
}
else {
a = false;
}
}

a = !a;

Or:

a ^= true;

--
John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
-- Charles Williams. "Taliessin through Logres: Prelude"


这篇关于布尔对立面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆