Add any, anyBy, all, allBy, none, noneBy

This commit is contained in:
Angelos Chalaris
2018-02-14 11:46:15 +02:00
parent 096fa381f0
commit dd9bbaac65
20 changed files with 1185 additions and 953 deletions

2
test/all/all.js Normal file
View File

@ -0,0 +1,2 @@
const all = arr => arr.every(Boolean);
module.exports = all;

19
test/all/all.test.js Normal file
View File

@ -0,0 +1,19 @@
const test = require('tape');
const all = require('./all.js');
test('Testing all', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof all === 'function', 'all is a Function');
t.true(all([4,1,2,3]), 'Returns true for arrays with no falsey values');
t.false(all([0,1]), 'Returns false for arrays with 0');
t.false(all([NaN,1]), 'Returns false for arrays with NaN');
t.false(all([undefined,1]), 'Returns false for arrays with undefined');
t.false(all([null,1]), 'Returns false for arrays with null');
t.false(all(['',1]), 'Returns false for arrays with empty strings');
//t.deepEqual(all(args..), 'Expected');
//t.equal(all(args..), 'Expected');
//t.false(all(args..), 'Expected');
//t.throws(all(args..), 'Expected');
t.end();
});

2
test/allBy/allBy.js Normal file
View File

@ -0,0 +1,2 @@
const allBy = (arr, fn) => arr.every(fn);
module.exports = allBy;

15
test/allBy/allBy.test.js Normal file
View File

@ -0,0 +1,15 @@
const test = require('tape');
const allBy = require('./allBy.js');
test('Testing allBy', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof allBy === 'function', 'allBy is a Function');
t.true(allBy([4,1,2,3], x => x >= 1), 'Returns true with predicate function');
t.false(allBy([0,1], x => x >= 1), 'Returns false with a predicate function');
//t.deepEqual(allBy(args..), 'Expected');
//t.equal(allBy(args..), 'Expected');
//t.false(allBy(args..), 'Expected');
//t.throws(allBy(args..), 'Expected');
t.end();
});

2
test/any/any.js Normal file
View File

@ -0,0 +1,2 @@
const any = arr => arr.some(Boolean);
module.exports = any;

16
test/any/any.test.js Normal file
View File

@ -0,0 +1,16 @@
const test = require('tape');
const any = require('./any.js');
test('Testing any', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof any === 'function', 'any is a Function');
t.true(any([0,1,2,3]), 'Returns true for arrays with at least one truthy value');
t.false(any([0,0]), 'Returns false for arrays with no truthy values');
t.false(any([NaN,0,undefined,null,'']), 'Returns false for arrays with no truthy values');
//t.deepEqual(any(args..), 'Expected');
//t.equal(any(args..), 'Expected');
//t.false(any(args..), 'Expected');
//t.throws(any(args..), 'Expected');
t.end();
});

2
test/anyBy/anyBy.js Normal file
View File

@ -0,0 +1,2 @@
const anyBy = (arr, fn) => arr.some(fn);
module.exports = anyBy;

15
test/anyBy/anyBy.test.js Normal file
View File

@ -0,0 +1,15 @@
const test = require('tape');
const anyBy = require('./anyBy.js');
test('Testing anyBy', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof anyBy === 'function', 'anyBy is a Function');
t.true(anyBy([4,1,0,3], x => x >= 1), 'Returns true with predicate function');
t.false(anyBy([0,1], x => x < 0), 'Returns false with a predicate function');
//t.deepEqual(anyBy(args..), 'Expected');
//t.equal(anyBy(args..), 'Expected');
//t.false(anyBy(args..), 'Expected');
//t.throws(anyBy(args..), 'Expected');
t.end();
});

2
test/none/none.js Normal file
View File

@ -0,0 +1,2 @@
const none = arr => !arr.some(Boolean);
module.exports = none;

15
test/none/none.test.js Normal file
View File

@ -0,0 +1,15 @@
const test = require('tape');
const none = require('./none.js');
test('Testing none', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof none === 'function', 'none is a Function');
t.true(none([0,undefined,NaN,null,'']), 'Returns true for arrays with no truthy values');
t.false(none([0,1]), 'Returns false for arrays with at least one truthy value');
//t.deepEqual(none(args..), 'Expected');
//t.equal(none(args..), 'Expected');
//t.false(none(args..), 'Expected');
//t.throws(none(args..), 'Expected');
t.end();
});

2
test/noneBy/noneBy.js Normal file
View File

@ -0,0 +1,2 @@
const noneBy = (arr, fn) => !arr.some(fn);
module.exports = noneBy;

View File

@ -0,0 +1,15 @@
const test = require('tape');
const noneBy = require('./noneBy.js');
test('Testing noneBy', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof noneBy === 'function', 'noneBy is a Function');
t.true(noneBy([4,1,0,3], x => x < 0), 'Returns true with a predicate function');
t.false(noneBy([0,1,2], x => x == 1), 'Returns false with predicate function');
//t.deepEqual(noneBy(args..), 'Expected');
//t.equal(noneBy(args..), 'Expected');
//t.false(noneBy(args..), 'Expected');
//t.throws(noneBy(args..), 'Expected');
t.end();
});

File diff suppressed because it is too large Load Diff