diff --git a/snippets/all.md b/snippets/all.md new file mode 100644 index 000000000..cb976da09 --- /dev/null +++ b/snippets/all.md @@ -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 +``` diff --git a/snippets/allBy.md b/snippets/allBy.md new file mode 100644 index 000000000..d2dec44f8 --- /dev/null +++ b/snippets/allBy.md @@ -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 +``` diff --git a/snippets/any.md b/snippets/any.md new file mode 100644 index 000000000..d030d4451 --- /dev/null +++ b/snippets/any.md @@ -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 +``` diff --git a/snippets/anyBy.md b/snippets/anyBy.md new file mode 100644 index 000000000..244c242d2 --- /dev/null +++ b/snippets/anyBy.md @@ -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 +``` diff --git a/snippets/none.md b/snippets/none.md new file mode 100644 index 000000000..8bf8fb830 --- /dev/null +++ b/snippets/none.md @@ -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 +``` diff --git a/snippets/noneBy.md b/snippets/noneBy.md new file mode 100644 index 000000000..20fcfcfb7 --- /dev/null +++ b/snippets/noneBy.md @@ -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 +``` diff --git a/tag_database b/tag_database index 09ba68764..42fd4810a 100644 --- a/tag_database +++ b/tag_database @@ -1,4 +1,8 @@ +all:array +allBy:array,function anagrams:string,recursion +any:array +anyBy:array,function approximatelyEqual:math arrayToHtmlList:browser,array ary:adapter,function @@ -159,6 +163,8 @@ merge:object,array minBy:math,array,function minN:array,math negate:function +none:array +noneBy:array,function nthArg:utility,function nthElement:array objectFromPairs:object,array diff --git a/test/all/all.js b/test/all/all.js new file mode 100644 index 000000000..1a938d602 --- /dev/null +++ b/test/all/all.js @@ -0,0 +1,2 @@ +const all = arr => arr.every(Boolean); +module.exports = all; \ No newline at end of file diff --git a/test/all/all.test.js b/test/all/all.test.js new file mode 100644 index 000000000..5aef8c036 --- /dev/null +++ b/test/all/all.test.js @@ -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(); +}); diff --git a/test/allBy/allBy.js b/test/allBy/allBy.js new file mode 100644 index 000000000..d222c885f --- /dev/null +++ b/test/allBy/allBy.js @@ -0,0 +1,2 @@ +const allBy = (arr, fn) => arr.every(fn); +module.exports = allBy; \ No newline at end of file diff --git a/test/allBy/allBy.test.js b/test/allBy/allBy.test.js new file mode 100644 index 000000000..29a018ba1 --- /dev/null +++ b/test/allBy/allBy.test.js @@ -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(); +}); diff --git a/test/any/any.js b/test/any/any.js new file mode 100644 index 000000000..701f7cc85 --- /dev/null +++ b/test/any/any.js @@ -0,0 +1,2 @@ +const any = arr => arr.some(Boolean); +module.exports = any; \ No newline at end of file diff --git a/test/any/any.test.js b/test/any/any.test.js new file mode 100644 index 000000000..d9dd8f3a5 --- /dev/null +++ b/test/any/any.test.js @@ -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(); +}); diff --git a/test/anyBy/anyBy.js b/test/anyBy/anyBy.js new file mode 100644 index 000000000..a72250185 --- /dev/null +++ b/test/anyBy/anyBy.js @@ -0,0 +1,2 @@ +const anyBy = (arr, fn) => arr.some(fn); +module.exports = anyBy; \ No newline at end of file diff --git a/test/anyBy/anyBy.test.js b/test/anyBy/anyBy.test.js new file mode 100644 index 000000000..126690349 --- /dev/null +++ b/test/anyBy/anyBy.test.js @@ -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(); +}); diff --git a/test/none/none.js b/test/none/none.js new file mode 100644 index 000000000..680ac9393 --- /dev/null +++ b/test/none/none.js @@ -0,0 +1,2 @@ +const none = arr => !arr.some(Boolean); +module.exports = none; \ No newline at end of file diff --git a/test/none/none.test.js b/test/none/none.test.js new file mode 100644 index 000000000..02d1a88a9 --- /dev/null +++ b/test/none/none.test.js @@ -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(); +}); diff --git a/test/noneBy/noneBy.js b/test/noneBy/noneBy.js new file mode 100644 index 000000000..21ae86e05 --- /dev/null +++ b/test/noneBy/noneBy.js @@ -0,0 +1,2 @@ +const noneBy = (arr, fn) => !arr.some(fn); +module.exports = noneBy; \ No newline at end of file diff --git a/test/noneBy/noneBy.test.js b/test/noneBy/noneBy.test.js new file mode 100644 index 000000000..f76aa990e --- /dev/null +++ b/test/noneBy/noneBy.test.js @@ -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(); +}); diff --git a/test/testlog b/test/testlog index 804151df6..8b77ecac0 100644 --- a/test/testlog +++ b/test/testlog @@ -1,9 +1,47 @@ +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) > 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 + √ Returns true for arrays with no falsey values + √ Returns false for arrays with 0 + √ Returns false for arrays with NaN + √ 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 + + Testing anagrams + + √ anagrams is a Function + √ Generates all anagrams of a string + √ Works for single-letter strings + √ Works for empty strings + + Testing any + + √ any is a Function + √ 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 @@ -1056,6 +1094,18 @@ Test log for: Wed Feb 14 2018 12:46:59 GMT+0200 (GTB Standard Time) √ negate is a Function √ Negates a predicate function + Testing none + + √ 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 + Testing nthArg √ nthArg is a Function @@ -1840,6 +1890,8 @@ Test log for: Wed Feb 14 2018 12:46:59 GMT+0200 (GTB Standard Time) Testing zipWith √ zipWith is a Function + √ Runs the function provided + √ Sends a GET request √ Sends a GET request √ Runs the function provided √ Runs promises in series