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

13
snippets/all.md Normal file
View File

@ -0,0 +1,13 @@
### all
Returns `true` if all elements in a collection are truthy, `false` otherwise.
Use `Array.every(Boolean)` to test if all elements in the collection are truthy.
```js
const all = arr => arr.every(Boolean);
```
```js
all([1,2,3]); // true
```

13
snippets/allBy.md Normal file
View File

@ -0,0 +1,13 @@
### allBy
Returns `true` if the provided predicate function returns `true` for all elements in a collection, `false` otherwise.
Use `Array.every()` to test if all elements in the collection return `true` based on `fn`.
```js
const allBy = (arr, fn) => arr.every(fn);
```
```js
allBy([4,2,3], x => x > 1); // true
```

13
snippets/any.md Normal file
View File

@ -0,0 +1,13 @@
### any
Returns `true` if at least one element in a collection is truthy, `false` otherwise.
Use `Array.some(Boolean)` to test if any elements in the collection are truthy.
```js
const any = arr => arr.some(Boolean);
```
```js
any([0,0,1,0]); // true
```

13
snippets/anyBy.md Normal file
View File

@ -0,0 +1,13 @@
### anyBy
Returns `true` if the provided predicate function returns `true` for at least one element in a collection, `false` otherwise.
Use `Array.some()` to test if any elements in the collection return `true` based on `fn`.
```js
const anyBy = (arr, fn) => arr.some(fn);
```
```js
anyBy([0,1,2,0], x => x >= 2); // true
```

13
snippets/none.md Normal file
View File

@ -0,0 +1,13 @@
### none
Returns `true` if no elements in a collection are truthy, `false` otherwise.
Use `!Array.some(Boolean)` to test if any elements in the collection are truthy.
```js
const none = arr => !arr.some(Boolean);
```
```js
none([0,0,0]); // true
```

13
snippets/noneBy.md Normal file
View File

@ -0,0 +1,13 @@
### noneBy
Returns `true` if the provided predicate function returns `false` for all elements in a collection, `false` otherwise.
Use `Array.some()` to test if any elements in the collection return `true` based on `fn`.
```js
const noneBy = (arr, fn) => !arr.some(fn);
```
```js
noneBy([0,1,3,0], x => x == 2); // true
```

View File

@ -1,4 +1,8 @@
all:array
allBy:array,function
anagrams:string,recursion anagrams:string,recursion
any:array
anyBy:array,function
arrayToHtmlList:browser,array arrayToHtmlList:browser,array
ary:adapter,function ary:adapter,function
atob:node,string,utility atob:node,string,utility
@ -154,6 +158,8 @@ merge:object,array
minBy:math,array,function minBy:math,array,function
minN:array,math minN:array,math
negate:function negate:function
none:array
noneBy:array,function
nthArg:utility,function nthArg:utility,function
nthElement:array nthElement:array
objectFromPairs:object,array objectFromPairs:object,array

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