Skip to content

Commit ab5168d

Browse files
committed
feat(logic): Implement nand
1 parent fddde48 commit ab5168d

3 files changed

Lines changed: 48 additions & 26 deletions

File tree

src/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,9 +980,10 @@ declare namespace RamdaAdjunct {
980980
neither(firstPredicate: Function, secondPredicate: Function): Function;
981981

982982
/**
983-
* Returns `true` if both arguments are falsy, otherwise `false`.
983+
* Returns true if both arguments are falsy; false otherwise.
984984
*/
985985
nand(a: any, b: any): Boolean;
986+
nand(a: any): (b: any) => Boolean;
986987

987988
/**
988989
* Takes a list of predicates and returns a predicate that returns true for a given list of

src/nand.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { and, complement } from 'ramda';
22

33
/**
4-
* Returns `true` if both arguments are falsy, otherwise `false`.
4+
* Returns true if both arguments are falsy; false otherwise.
55
*
66
* @func nand
77
* @memberOf RA
@@ -10,19 +10,18 @@ import { and, complement } from 'ramda';
1010
* @sig a -> b -> Boolean
1111
* @param {Boolean} a
1212
* @param {Boolean} b
13-
* @return {Boolean} True if both arguments are false.
13+
* @return {Boolean} true if both arguments are false
1414
* @example
1515
*
16-
* RA.nand(True, True); //=> False
17-
* RA.nand(False, True); //=> True
18-
* RA.nand(True, False); //=> True
19-
* RA.nand(False, False); //=> True
20-
* RA.nand(1.0, 1.0); //=> False
21-
* RA.nand(1.0, 0); //=> True
22-
* RA.nand(0, 1.0); //=> True
23-
* RA.nand(0, 0); //=> True
16+
* RA.nand(true, true); //=> false
17+
* RA.nand(false, true); //=> true
18+
* RA.nand(true, false); //=> true
19+
* RA.nand(false, false); //=> true
20+
* RA.nand(1.0, 1.0); //=> false
21+
* RA.nand(1.0, 0); //=> true
22+
* RA.nand(0, 1.0); //=> true
23+
* RA.nand(0, 0); //=> true
2424
*/
25-
26-
const nand = complement(and);
25+
const nand = complement(and); // eslint-disable-line ramda/complement-simplification
2726

2827
export default nand;

test/nand.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
1-
import * as R from 'ramda';
21
import eq from './shared/eq';
3-
import { nand } from '../src';
2+
import * as RA from '../src';
43

5-
describe('nand', () => {
6-
it('compared two values with nand', () => {
7-
eq(nand(true, true), false);
8-
eq(nand(false, true), true);
9-
eq(nand(true, false), true);
10-
eq(nand(false, false), true);
11-
eq(nand(1.0, 1.0), false);
12-
eq(nand(0.0, 1.0), true);
13-
eq(nand(1.0, 0.0), true);
14-
eq(nand(0.0, 0.0), true);
4+
describe('RA.nand', function() {
5+
it('should work on booleans', function() {
6+
eq(RA.nand(true, true), false);
7+
eq(RA.nand(false, true), true);
8+
eq(RA.nand(true, false), true);
9+
eq(RA.nand(false, false), true);
1510
});
16-
});
11+
12+
it('should work on numbers', function() {
13+
eq(RA.nand(1.0, 1.0), false);
14+
eq(RA.nand(0.0, 1.0), true);
15+
eq(RA.nand(1.0, 0.0), true);
16+
eq(RA.nand(0.0, 0.0), true);
17+
});
18+
19+
it('should work on a combination of things', function() {
20+
eq(RA.nand(true, 1.0), false);
21+
eq(RA.nand(null, true), true);
22+
eq(RA.nand(1.0, undefined), true);
23+
eq(RA.nand(0.0, false), true);
24+
eq(RA.nand(null, null), true);
25+
eq(RA.nand(null, undefined), true);
26+
});
27+
28+
it('should support currying', function() {
29+
eq(RA.nand(true, true), false);
30+
eq(RA.nand(true)(true), false);
31+
eq(RA.nand(false, true), true);
32+
eq(RA.nand(false)(true), true);
33+
eq(RA.nand(true, false), true);
34+
eq(RA.nand(true)(false), true);
35+
eq(RA.nand(false, false), true);
36+
eq(RA.nand(false)(false), true);
37+
});
38+
});

0 commit comments

Comments
 (0)