Skip to content

Commit

Permalink
feat(logic): Implement nand
Browse files Browse the repository at this point in the history
  • Loading branch information
dawehner committed Jun 10, 2019
1 parent fddde48 commit cb90bd4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
23 changes: 11 additions & 12 deletions src/nand.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { and, complement } from 'ramda';

/**
* Returns `true` if both arguments are falsy, otherwise `false`.
* Returns true if both arguments are falsy; false otherwise.
*
* @func nand
* @memberOf RA
Expand All @@ -10,19 +10,18 @@ import { and, complement } from 'ramda';
* @sig a -> b -> Boolean
* @param {Boolean} a
* @param {Boolean} b
* @return {Boolean} True if both arguments are false.
* @return {Boolean} true if both arguments are false
* @example
*
* RA.nand(True, True); //=> False
* RA.nand(False, True); //=> True
* RA.nand(True, False); //=> True
* RA.nand(False, False); //=> True
* RA.nand(1.0, 1.0); //=> False
* RA.nand(1.0, 0); //=> True
* RA.nand(0, 1.0); //=> True
* RA.nand(0, 0); //=> True
* RA.nand(true, true); //=> false
* RA.nand(false, true); //=> true
* RA.nand(true, false); //=> true
* RA.nand(false, false); //=> true
* RA.nand(1.0, 1.0); //=> false
* RA.nand(1.0, 0); //=> true
* RA.nand(0, 1.0); //=> true
* RA.nand(0, 0); //=> true
*/

const nand = complement(and);
const nand = complement(and); // eslint-disable-line ramda/complement-simplification

export default nand;
19 changes: 15 additions & 4 deletions test/nand.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import * as R from 'ramda';
import eq from './shared/eq';
import { nand } from '../src';

describe('nand', () => {
it('compared two values with nand', () => {
describe('nand', function() {
it('should work on booleans', function() {
eq(nand(true, true), false);
eq(nand(false, true), true);
eq(nand(true, false), true);
eq(nand(false, false), true);
});

it('should work on numbers', function() {
eq(nand(1.0, 1.0), false);
eq(nand(0.0, 1.0), true);
eq(nand(1.0, 0.0), true);
eq(nand(0.0, 0.0), true);
});
});

it('should work on a combination of things', function() {
eq(nand(true, 1.0), false);
eq(nand(null, true), true);
eq(nand(1.0, undefined), true);
eq(nand(0.0, false), true);
eq(nand(null, null), true);
eq(nand(null, undefined), true);
});
});

0 comments on commit cb90bd4

Please sign in to comment.