Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added not versions of boolean operators #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/boolean/and.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
export function and (
right : boolean,
) : boolean {
return this && right;
return Boolean(this) && Boolean(right);
};
16 changes: 16 additions & 0 deletions src/boolean/identity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Returns the identity of the boolean.
*
* @this {boolean} The boolean.
* @example Basic Usage
*
* ```javascript
* true::identity() // true
* false::identity() // false
* ```
*/
export function identity (

) : boolean {
return Boolean(this);
};
19 changes: 19 additions & 0 deletions src/boolean/nand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Returns true if both operands are not true.
*
* @this {boolean} Left boolean operand.
* @param right Right boolean operand.
* @example Basic Usage
*
* ```javascript
* true::nand(true) // false
* true::nand(false) // true
* false::nand(true) // true
* false::nand(false) // true
* ```
*/
export function nand (
right : boolean,
) : boolean {
return !(Boolean(this) && Boolean(right));
};
19 changes: 19 additions & 0 deletions src/boolean/nor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Returns true if neither of the operands are true.
*
* @this {boolean} Left boolean operand.
* @param right Right boolean operand.
* @example Basic Usage
*
* ```javascript
* true::nor(true) // false
* true::nor(false) // false
* false::nor(true) // false
* false::nor(false) // true
* ```
*/
export function nor (
right : boolean,
) : boolean {
return !(Boolean(this) || Boolean(right));
};
4 changes: 2 additions & 2 deletions src/boolean/or.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Returns true if either of the operands is true.
* Returns true if either operand is true.
*
* @this {boolean} Left boolean operand.
* @param right Right boolean operand.
Expand All @@ -15,5 +15,5 @@
export function or (
right : boolean,
) : boolean {
return this || right;
return Boolean(this) || Boolean(right);
};
19 changes: 19 additions & 0 deletions src/boolean/xnor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Returns true if both operands are true or both operands are false.
*
* @this {boolean} Left boolean operand.
* @param right Right boolean operand.
* @example Basic Usage
*
* ```javascript
* true::xnor(true) // false
* true::xnor(false) // true
* false::xnor(true) // true
* false::xnor(false) // false
* ```
*/
export function xnor (
right : boolean,
) : boolean {
return Boolean(this) === Boolean(right);
};
4 changes: 2 additions & 2 deletions src/boolean/xor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Returns true if one and only one of the conditions is true.
* Returns true if and only if one operand is true.
*
* @this {boolean} Left boolean operand.
* @param right Right boolean operand.
Expand All @@ -15,5 +15,5 @@
export function xor (
right : boolean,
) : boolean {
return this !== right;
return Boolean(this) !== Boolean(right);
};
2 changes: 1 addition & 1 deletion src/function/partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function countPlaceholders () {
}

function flatMap (transformer) {
return [].concat.apply([], this.map(transformer));
return Array.prototype.concat.apply([], this.map(transformer));
}

/**
Expand Down
15 changes: 15 additions & 0 deletions test/spec/boolean/identitySpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { identity } from "../../../src/boolean/identity";

describe("identity()", function () {
describe("with true", function () {
it("should return true", function () {
true::identity().should.equal(true);
});
});

describe("with false", function () {
it("should return false", function () {
false::identity().should.equal(false);
});
});
});
27 changes: 27 additions & 0 deletions test/spec/boolean/nandSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { nand } from "../../../src/boolean/nand";

describe("nand()", function () {
describe("with true and true", function () {
it("should return false", function () {
true::nand(true).should.equal(false);
});
});

describe("with true and false", function () {
it("should return true", function () {
true::nand(false).should.equal(true);
});
});

describe("with false and true", function () {
it("should return true", function () {
false::nand(true).should.equal(true);
});
});

describe("with false and false", function () {
it("should return true", function () {
false::nand(false).should.equal(true);
});
});
});
27 changes: 27 additions & 0 deletions test/spec/boolean/norSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { nor } from "../../../src/boolean/nor";

describe("nor()", function () {
describe("with true and true", function () {
it("should return false", function () {
true::nor(true).should.equal(false);
});
});

describe("with true and false", function () {
it("should return false", function () {
true::nor(false).should.equal(false);
});
});

describe("with false and true", function () {
it("should return false", function () {
false::nor(true).should.equal(false);
});
});

describe("with false and false", function () {
it("should return true", function () {
false::nor(false).should.equal(true);
});
});
});
27 changes: 27 additions & 0 deletions test/spec/boolean/xnorSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { xnor } from "../../../src/boolean/xnor";

describe("xnor()", function () {
describe("with true and true", function () {
it("should return true", function () {
true::xnor(true).should.equal(true);
});
});

describe("with true and false", function () {
it("should return false", function () {
true::xnor(false).should.equal(false);
});
});

describe("with false and true", function () {
it("should return false", function () {
false::xnor(true).should.equal(false);
});
});

describe("with false and false", function () {
it("should return true", function () {
false::xnor(false).should.equal(true);
});
});
});
6 changes: 3 additions & 3 deletions test/spec/boolean/xorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { xor } from "../../../src/boolean/xor";

describe("xor()", function () {
describe("with true and true", function () {
it("should return true", function () {
it("should return false", function () {
true::xor(true).should.equal(false);
});
});

describe("with true and false", function () {
it("should return false", function () {
it("should return true", function () {
true::xor(false).should.equal(true);
});
});

describe("with false and true", function () {
it("should return false", function () {
it("should return true", function () {
false::xor(true).should.equal(true);
});
});
Expand Down