Add bifurcate, bifurcateBy
This commit is contained in:
6
test/bifurcate/bifurcate.js
Normal file
6
test/bifurcate/bifurcate.js
Normal file
@ -0,0 +1,6 @@
|
||||
const bifurcate = (arr, filter) =>
|
||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [
|
||||
[],
|
||||
[],
|
||||
]);
|
||||
module.exports = bifurcate;
|
||||
14
test/bifurcate/bifurcate.test.js
Normal file
14
test/bifurcate/bifurcate.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const test = require('tape');
|
||||
const bifurcate = require('./bifurcate.js');
|
||||
|
||||
test('Testing bifurcate', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof bifurcate === 'function', 'bifurcate is a Function');
|
||||
t.deepEqual(bifurcate([ 'beep', 'boop', 'foo', 'bar' ], [ true, true, false, true ]), [ ['beep', 'boop', 'bar'], ['foo'] ], 'Splits the collection into two groups');
|
||||
//t.deepEqual(bifurcate(args..), 'Expected');
|
||||
//t.equal(bifurcate(args..), 'Expected');
|
||||
//t.false(bifurcate(args..), 'Expected');
|
||||
//t.throws(bifurcate(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
6
test/bifurcateBy/bifurcateBy.js
Normal file
6
test/bifurcateBy/bifurcateBy.js
Normal file
@ -0,0 +1,6 @@
|
||||
const bifurcateBy = (arr, fn) =>
|
||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [
|
||||
[],
|
||||
[],
|
||||
]);
|
||||
module.exports = bifurcateBy;
|
||||
14
test/bifurcateBy/bifurcateBy.test.js
Normal file
14
test/bifurcateBy/bifurcateBy.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const test = require('tape');
|
||||
const bifurcateBy = require('./bifurcateBy.js');
|
||||
|
||||
test('Testing bifurcateBy', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof bifurcateBy === 'function', 'bifurcateBy is a Function');
|
||||
t.deepEqual(bifurcateBy([ 'beep', 'boop', 'foo', 'bar' ], x => x[0] === 'b'), [ ['beep', 'boop', 'bar'], ['foo'] ], 'Splits the collection into two groups');
|
||||
//t.deepEqual(bifurcateBy(args..), 'Expected');
|
||||
//t.equal(bifurcateBy(args..), 'Expected');
|
||||
//t.false(bifurcateBy(args..), 'Expected');
|
||||
//t.throws(bifurcateBy(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
18
test/testlog
18
test/testlog
@ -1,4 +1,4 @@
|
||||
Test log for: Wed Feb 14 2018 11:56:24 GMT+0200 (GTB Standard Time)
|
||||
Test log for: Wed Feb 14 2018 12:12:48 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
|
||||
@ -53,6 +53,16 @@ Test log for: Wed Feb 14 2018 11:56:24 GMT+0200 (GTB Standard Time)
|
||||
√ Produces the right result with a function
|
||||
√ Produces the right result with a property name
|
||||
|
||||
Testing bifurcate
|
||||
|
||||
√ bifurcate is a Function
|
||||
√ Splits the collection into two groups
|
||||
|
||||
Testing bifurcateBy
|
||||
|
||||
√ bifurcateBy is a Function
|
||||
√ Splits the collection into two groups
|
||||
|
||||
Testing binarySearch
|
||||
|
||||
√ binarySearch is a Function
|
||||
@ -1803,15 +1813,15 @@ Test log for: Wed Feb 14 2018 11:56:24 GMT+0200 (GTB Standard Time)
|
||||
Testing zipWith
|
||||
|
||||
√ zipWith is a Function
|
||||
√ Runs the function provided
|
||||
√ Sends a GET request
|
||||
√ Runs the function provided
|
||||
√ Runs promises in series
|
||||
√ Sends a POST request
|
||||
√ Works with multiple promises
|
||||
|
||||
|
||||
total: 905
|
||||
passing: 905
|
||||
total: 909
|
||||
passing: 909
|
||||
duration: 2.4s
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user