-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organize files and fix "and" and "or" function to receive multiple args
- Loading branch information
1 parent
06c75f5
commit 2473d08
Showing
9 changed files
with
58 additions
and
134 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Compare if there is truthy value. | ||
* Return true if all values are truthy. | ||
* | ||
* @example | ||
* and(false, false, false); // false | ||
* and(true, false, false); // false | ||
* and(true, false, true); // false | ||
* and(true, true, true); // true | ||
* | ||
* @param {any} args - values to check | ||
* @returns {boolean} | ||
*/ | ||
export function and(...args) { | ||
for (let i = 0; i < args.length; i++) { | ||
if (!args[i]) return false; | ||
} | ||
return true; | ||
}; | ||
|
||
/** | ||
* Compare if one of the value are truthy. | ||
* Return true if one are truthy. | ||
* | ||
* @example | ||
* or(false, false, false); // false | ||
* or(true, false, true); // true | ||
* or(false, true, false); // true | ||
* or(true, true, true); // true | ||
* | ||
* @param {any} args - values to check | ||
* @returns {boolean} | ||
*/ | ||
export function or(...args) { return !!args.find(a => !!a) }; | ||
|
||
/** | ||
* Return false if both values are truthy ou falsy. | ||
* | ||
* @example | ||
* xor(false, false); // false | ||
* xor(true, false); // true | ||
* xor(false, true); // true | ||
* xor(true, true); // false | ||
* | ||
* @param {any} value1 - value 1 to compare | ||
* @param {any} value2 - value 2 to compare | ||
* @returns {boolean} | ||
*/ | ||
export function xor(value1, value2) { return !!value1 !== !!value2 }; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.