Is there anyway to implement XOR in javascript

前端 未结 18 687
孤城傲影
孤城傲影 2020-12-24 10:53

I\'m trying to implement XOR in javascript in the following way:

   // XOR validation
   if ((isEmptyString(firstStr) && !isEmptyString(secondStr)) |         


        
18条回答
  •  一向
    一向 (楼主)
    2020-12-24 11:32

    You could do this:

    Math.abs( isEmptyString(firstStr) - isEmptyString(secondStr) )
    

    The result of that is the result of a XOR operation.

提交回复
热议问题