Updated all, any, none
Merged them with their by counterparts.
This commit is contained in:
@ -1,13 +1,15 @@
|
||||
### all
|
||||
|
||||
Returns `true` if all elements in a collection are truthy, `false` otherwise.
|
||||
Returns `true` if the provided predicate function returns `true` for all elements in a collection, `false` otherwise.
|
||||
|
||||
Use `Array.every(Boolean)` to test if all elements in the collection are truthy.
|
||||
Use `Array.every()` to test if all elements in the collection return `true` based on `fn`.
|
||||
Omit the second argument, `fn`, to use `Boolean` as a default.
|
||||
|
||||
```js
|
||||
const all = arr => arr.every(Boolean);
|
||||
const all = (arr, fn = Boolean) => arr.every(fn);
|
||||
```
|
||||
|
||||
```js
|
||||
all([4, 2, 3], x => x > 1); // true
|
||||
all([1, 2, 3]); // true
|
||||
```
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
### 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
|
||||
```
|
||||
@ -1,13 +1,15 @@
|
||||
### any
|
||||
|
||||
Returns `true` if at least one element in a collection is truthy, `false` otherwise.
|
||||
Returns `true` if the provided predicate function returns `true` for at least one element in a collection, `false` otherwise.
|
||||
|
||||
Use `Array.some(Boolean)` to test if any elements in the collection are truthy.
|
||||
Use `Array.some()` to test if any elements in the collection return `true` based on `fn`.
|
||||
Omit the second argument, `fn`, to use `Boolean` as a default.
|
||||
|
||||
```js
|
||||
const any = arr => arr.some(Boolean);
|
||||
const any = (arr, fn = Boolean) => arr.some(fn);
|
||||
```
|
||||
|
||||
```js
|
||||
any([0, 1, 2, 0], x => x >= 2); // true
|
||||
any([0, 0, 1, 0]); // true
|
||||
```
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
### 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
|
||||
```
|
||||
@ -1,13 +1,15 @@
|
||||
### none
|
||||
|
||||
Returns `true` if no elements in a collection are truthy, `false` otherwise.
|
||||
Returns `true` if the provided predicate function returns `false` for all elements in a collection, `false` otherwise.
|
||||
|
||||
Use `!Array.some(Boolean)` to test if any elements in the collection are truthy.
|
||||
Use `Array.some()` to test if any elements in the collection return `true` based on `fn`.
|
||||
Omit the second argument, `fn`, to use `Boolean` as a default.
|
||||
|
||||
```js
|
||||
const none = arr => !arr.some(Boolean);
|
||||
const none = (arr, fn = Boolean) => !arr.some(fn);
|
||||
```
|
||||
|
||||
```js
|
||||
none([0, 1, 3, 0], x => x == 2); // true
|
||||
none([0, 0, 0]); // true
|
||||
```
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
### 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
|
||||
```
|
||||
@ -1,8 +1,6 @@
|
||||
all:array
|
||||
allBy:array,function
|
||||
all:array,function
|
||||
anagrams:string,recursion
|
||||
any:array
|
||||
anyBy:array,function
|
||||
any:array,function
|
||||
approximatelyEqual:math
|
||||
arrayToHtmlList:browser,array
|
||||
ary:adapter,function
|
||||
@ -164,8 +162,7 @@ minBy:math,array,function
|
||||
minN:array,math
|
||||
mostPerformant:utility,function
|
||||
negate:function
|
||||
none:array
|
||||
noneBy:array,function
|
||||
none:array,function
|
||||
nthArg:utility,function
|
||||
nthElement:array
|
||||
objectFromPairs:object,array
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
const all = arr => arr.every(Boolean);
|
||||
const all = (arr, fn = Boolean) => arr.every(fn);
|
||||
module.exports = all;
|
||||
@ -11,6 +11,8 @@ test('Testing all', (t) => {
|
||||
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.true(all([4,1,2,3], x => x >= 1), 'Returns true with predicate function');
|
||||
t.false(all([0,1], x => x >= 1), 'Returns false with a predicate function');
|
||||
//t.deepEqual(all(args..), 'Expected');
|
||||
//t.equal(all(args..), 'Expected');
|
||||
//t.false(all(args..), 'Expected');
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
const allBy = (arr, fn) => arr.every(fn);
|
||||
module.exports = allBy;
|
||||
@ -1,15 +0,0 @@
|
||||
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();
|
||||
});
|
||||
@ -1,2 +1,2 @@
|
||||
const any = arr => arr.some(Boolean);
|
||||
const any = (arr, fn = Boolean) => arr.some(fn);
|
||||
module.exports = any;
|
||||
@ -8,6 +8,8 @@ test('Testing any', (t) => {
|
||||
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.true(any([4,1,0,3], x => x >= 1), 'Returns true with predicate function');
|
||||
t.false(any([0,1], x => x < 0), 'Returns false with a predicate function');
|
||||
//t.deepEqual(any(args..), 'Expected');
|
||||
//t.equal(any(args..), 'Expected');
|
||||
//t.false(any(args..), 'Expected');
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
const anyBy = (arr, fn) => arr.some(fn);
|
||||
module.exports = anyBy;
|
||||
@ -1,15 +0,0 @@
|
||||
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();
|
||||
});
|
||||
9
test/mostPerformant/mostPerformant.js
Normal file
9
test/mostPerformant/mostPerformant.js
Normal file
@ -0,0 +1,9 @@
|
||||
const mostPerformant = (fns, iterations = 10000) => {
|
||||
const times = fns.map(fn => {
|
||||
const before = performance.now();
|
||||
for (let i = 0; i < iterations; i++) fn();
|
||||
return performance.now() - before;
|
||||
});
|
||||
return times.indexOf(Math.min(...times));
|
||||
};
|
||||
module.exports = mostPerformant;
|
||||
14
test/mostPerformant/mostPerformant.test.js
Normal file
14
test/mostPerformant/mostPerformant.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const test = require('tape');
|
||||
const mostPerformant = require('./mostPerformant.js');
|
||||
|
||||
test('Testing mostPerformant', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof mostPerformant === 'function', 'mostPerformant is a Function');
|
||||
t.pass('Tested by @chalarangelo on 16/02/2018');
|
||||
//t.deepEqual(mostPerformant(args..), 'Expected');
|
||||
//t.equal(mostPerformant(args..), 'Expected');
|
||||
//t.false(mostPerformant(args..), 'Expected');
|
||||
//t.throws(mostPerformant(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
@ -1,2 +1,2 @@
|
||||
const none = arr => !arr.some(Boolean);
|
||||
const none = (arr, fn = Boolean) => !arr.some(fn);
|
||||
module.exports = none;
|
||||
@ -7,6 +7,8 @@ test('Testing none', (t) => {
|
||||
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.true(none([4,1,0,3], x => x < 0), 'Returns true with a predicate function');
|
||||
t.false(none([0,1,2], x => x === 1), 'Returns false with predicate function');
|
||||
//t.deepEqual(none(args..), 'Expected');
|
||||
//t.equal(none(args..), 'Expected');
|
||||
//t.false(none(args..), 'Expected');
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
const noneBy = (arr, fn) => !arr.some(fn);
|
||||
module.exports = noneBy;
|
||||
@ -1,15 +0,0 @@
|
||||
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();
|
||||
});
|
||||
35
test/testlog
35
test/testlog
@ -1,11 +1,9 @@
|
||||
Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
Test log for: Wed Feb 14 2018 12:46:59 GMT+0200 (GTB Standard Time)
|
||||
Test log for: Fri Feb 16 2018 13:42:15 GMT+0200 (GTB Standard Time)
|
||||
|
||||
> 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code
|
||||
> tape test/**/*.test.js | tap-spec
|
||||
|
||||
|
||||
|
||||
Testing all
|
||||
|
||||
√ all is a Function
|
||||
@ -15,10 +13,6 @@ Test log for: Wed Feb 14 2018 12:46:59 GMT+0200 (GTB Standard Time)
|
||||
√ Returns false for arrays with undefined
|
||||
√ Returns false for arrays with null
|
||||
√ Returns false for arrays with empty strings
|
||||
|
||||
Testing allBy
|
||||
|
||||
√ allBy is a Function
|
||||
√ Returns true with predicate function
|
||||
√ Returns false with a predicate function
|
||||
|
||||
@ -35,20 +29,9 @@ Test log for: Wed Feb 14 2018 12:46:59 GMT+0200 (GTB Standard Time)
|
||||
√ Returns true for arrays with at least one truthy value
|
||||
√ Returns false for arrays with no truthy values
|
||||
√ Returns false for arrays with no truthy values
|
||||
|
||||
Testing anyBy
|
||||
|
||||
√ anyBy is a Function
|
||||
√ Returns true with predicate function
|
||||
√ Returns false with a predicate function
|
||||
|
||||
Testing anagrams
|
||||
|
||||
√ anagrams is a Function
|
||||
√ Generates all anagrams of a string
|
||||
√ Works for single-letter strings
|
||||
√ Works for empty strings
|
||||
|
||||
Testing approximatelyEqual
|
||||
|
||||
√ approximatelyEqual is a Function
|
||||
@ -1089,6 +1072,10 @@ Test log for: Wed Feb 14 2018 12:46:59 GMT+0200 (GTB Standard Time)
|
||||
√ Returns the n minimum elements from the provided array
|
||||
√ Returns the n minimum elements from the provided array
|
||||
|
||||
Testing mostPerformant
|
||||
|
||||
√ mostPerformant is a Function
|
||||
|
||||
Testing negate
|
||||
|
||||
√ negate is a Function
|
||||
@ -1099,10 +1086,6 @@ Test log for: Wed Feb 14 2018 12:46:59 GMT+0200 (GTB Standard Time)
|
||||
√ none is a Function
|
||||
√ Returns true for arrays with no truthy values
|
||||
√ Returns false for arrays with at least one truthy value
|
||||
|
||||
Testing noneBy
|
||||
|
||||
√ noneBy is a Function
|
||||
√ Returns true with a predicate function
|
||||
√ Returns false with predicate function
|
||||
|
||||
@ -1892,15 +1875,13 @@ Test log for: Wed Feb 14 2018 12:46:59 GMT+0200 (GTB Standard Time)
|
||||
√ zipWith is a Function
|
||||
√ Runs the function provided
|
||||
√ Sends a GET request
|
||||
√ Sends a GET request
|
||||
√ Runs the function provided
|
||||
√ Runs promises in series
|
||||
√ Sends a POST request
|
||||
√ Works with multiple promises
|
||||
|
||||
|
||||
total: 924
|
||||
passing: 924
|
||||
duration: 2.5s
|
||||
total: 945
|
||||
passing: 945
|
||||
duration: 4.9s
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user