Merge pull request #1331 from Bhaskar-maity/master

Added xor.md
This commit is contained in:
Angelos Chalaris
2020-10-06 19:09:54 +03:00
committed by GitHub

19
snippets/xor.md Normal file
View File

@ -0,0 +1,19 @@
---
title: xor
tags: math,logic,beginner
---
Returns `true` if only one of the arguments is `true`, `false` otherwise.
- Use the logical or (`||`), and (`&&`) and not (`!`) operators on the two given values to create the logical xor.
```js
const xor = (a, b) => (( a || b ) && !( a && b ));
```
```js
xor(true, true); // false
xor(true, false); // true
xor(false, true); // true
xor(false, false); // false
```