From 9a3bd8ffae064f1e4dceed5ea7959ee054afd01c Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 16 Feb 2018 13:43:43 +0200 Subject: [PATCH] Updated all, any, none Merged them with their by counterparts. --- snippets/all.md | 8 +++-- snippets/allBy.md | 13 -------- snippets/any.md | 8 +++-- snippets/anyBy.md | 13 -------- snippets/none.md | 8 +++-- snippets/noneBy.md | 13 -------- tag_database | 9 ++---- test/all/all.js | 2 +- test/all/all.test.js | 2 ++ test/allBy/allBy.js | 2 -- test/allBy/allBy.test.js | 15 ---------- test/any/any.js | 2 +- test/any/any.test.js | 2 ++ test/anyBy/anyBy.js | 2 -- test/anyBy/anyBy.test.js | 15 ---------- test/mostPerformant/mostPerformant.js | 9 ++++++ test/mostPerformant/mostPerformant.test.js | 14 +++++++++ test/none/none.js | 2 +- test/none/none.test.js | 2 ++ test/noneBy/noneBy.js | 2 -- test/noneBy/noneBy.test.js | 15 ---------- test/testlog | 35 +++++----------------- 22 files changed, 58 insertions(+), 135 deletions(-) delete mode 100644 snippets/allBy.md delete mode 100644 snippets/anyBy.md delete mode 100644 snippets/noneBy.md delete mode 100644 test/allBy/allBy.js delete mode 100644 test/allBy/allBy.test.js delete mode 100644 test/anyBy/anyBy.js delete mode 100644 test/anyBy/anyBy.test.js create mode 100644 test/mostPerformant/mostPerformant.js create mode 100644 test/mostPerformant/mostPerformant.test.js delete mode 100644 test/noneBy/noneBy.js delete mode 100644 test/noneBy/noneBy.test.js diff --git a/snippets/all.md b/snippets/all.md index e9faecd9d..17cadbc9f 100644 --- a/snippets/all.md +++ b/snippets/all.md @@ -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 ``` diff --git a/snippets/allBy.md b/snippets/allBy.md deleted file mode 100644 index 36335714f..000000000 --- a/snippets/allBy.md +++ /dev/null @@ -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 -``` diff --git a/snippets/any.md b/snippets/any.md index 09a5afad8..31368cc7a 100644 --- a/snippets/any.md +++ b/snippets/any.md @@ -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 ``` diff --git a/snippets/anyBy.md b/snippets/anyBy.md deleted file mode 100644 index 2345f82bc..000000000 --- a/snippets/anyBy.md +++ /dev/null @@ -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 -``` diff --git a/snippets/none.md b/snippets/none.md index a243b0409..1b9af0c2a 100644 --- a/snippets/none.md +++ b/snippets/none.md @@ -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 ``` diff --git a/snippets/noneBy.md b/snippets/noneBy.md deleted file mode 100644 index fa719d2df..000000000 --- a/snippets/noneBy.md +++ /dev/null @@ -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 -``` diff --git a/tag_database b/tag_database index 13f4d7cc9..df3662150 100644 --- a/tag_database +++ b/tag_database @@ -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 diff --git a/test/all/all.js b/test/all/all.js index 1a938d602..6be892a3c 100644 --- a/test/all/all.js +++ b/test/all/all.js @@ -1,2 +1,2 @@ -const all = arr => arr.every(Boolean); +const all = (arr, fn = Boolean) => arr.every(fn); module.exports = all; \ No newline at end of file diff --git a/test/all/all.test.js b/test/all/all.test.js index 5aef8c036..60ac82f4a 100644 --- a/test/all/all.test.js +++ b/test/all/all.test.js @@ -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'); diff --git a/test/allBy/allBy.js b/test/allBy/allBy.js deleted file mode 100644 index d222c885f..000000000 --- a/test/allBy/allBy.js +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 29a018ba1..000000000 --- a/test/allBy/allBy.test.js +++ /dev/null @@ -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(); -}); diff --git a/test/any/any.js b/test/any/any.js index 701f7cc85..5004b3309 100644 --- a/test/any/any.js +++ b/test/any/any.js @@ -1,2 +1,2 @@ -const any = arr => arr.some(Boolean); +const any = (arr, fn = Boolean) => arr.some(fn); module.exports = any; \ No newline at end of file diff --git a/test/any/any.test.js b/test/any/any.test.js index d9dd8f3a5..63399b385 100644 --- a/test/any/any.test.js +++ b/test/any/any.test.js @@ -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'); diff --git a/test/anyBy/anyBy.js b/test/anyBy/anyBy.js deleted file mode 100644 index a72250185..000000000 --- a/test/anyBy/anyBy.js +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 126690349..000000000 --- a/test/anyBy/anyBy.test.js +++ /dev/null @@ -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(); -}); diff --git a/test/mostPerformant/mostPerformant.js b/test/mostPerformant/mostPerformant.js new file mode 100644 index 000000000..ae084a5cf --- /dev/null +++ b/test/mostPerformant/mostPerformant.js @@ -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; \ No newline at end of file diff --git a/test/mostPerformant/mostPerformant.test.js b/test/mostPerformant/mostPerformant.test.js new file mode 100644 index 000000000..95a560f91 --- /dev/null +++ b/test/mostPerformant/mostPerformant.test.js @@ -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(); +}); diff --git a/test/none/none.js b/test/none/none.js index 680ac9393..2e81d7d72 100644 --- a/test/none/none.js +++ b/test/none/none.js @@ -1,2 +1,2 @@ -const none = arr => !arr.some(Boolean); +const none = (arr, fn = Boolean) => !arr.some(fn); module.exports = none; \ No newline at end of file diff --git a/test/none/none.test.js b/test/none/none.test.js index 02d1a88a9..af6209d91 100644 --- a/test/none/none.test.js +++ b/test/none/none.test.js @@ -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'); diff --git a/test/noneBy/noneBy.js b/test/noneBy/noneBy.js deleted file mode 100644 index 21ae86e05..000000000 --- a/test/noneBy/noneBy.js +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index f76aa990e..000000000 --- a/test/noneBy/noneBy.test.js +++ /dev/null @@ -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(); -}); diff --git a/test/testlog b/test/testlog index 8b77ecac0..6bc0d1ffb 100644 --- a/test/testlog +++ b/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,19 +29,8 @@ 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 @@ -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