Adapter
ary
Creates a function that accepts up to n arguments, ignoring any additional arguments.
Call the provided function, fn, with up to n arguments, using Array.slice(0,n) and the spread operator (...).
const ary = (fn, n) => (...args) => fn(...args.slice(0, n)); + }
30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.
Adapter
ary
Creates a function that accepts up to
narguments, ignoring any additional arguments.Call the provided function,
fn, with up tonarguments, usingArray.slice(0,n)and the spread operator (...).const ary = (fn, n) => (...args) => fn(...args.slice(0, n));const firstTwoMax = ary(Math.max, 2); [[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10]call
Given a key and a set of arguments, call them when given a context. Primarily useful in composition.
Use a closure to call a stored key with stored arguments.
const call = (key, ...args) => context => context[key](...args); @@ -123,14 +123,12 @@ Object.assig arrayMax([1, 2, 3]); // 3unary
Creates a function that accepts up to one argument, ignoring any additional arguments.
Call the provided function,
fn, with just the first argument given.const unary = fn => val => fn(val);['6', '8', '10'].map(unary(parseInt)); // [6, 8, 10] -Array
all
Returns
trueif all elements in a collection are truthy,falseotherwise.Use
Array.every(Boolean)to test if all elements in the collection are truthy.const all = arr => arr.every(Boolean); -all([1, 2, 3]); // true -allBy
Returns
trueif the provided predicate function returnstruefor all elements in a collection,falseotherwise.Use
Array.every()to test if all elements in the collection returntruebased onfn.const allBy = (arr, fn) => arr.every(fn); -allBy([4, 2, 3], x => x > 1); // true -any
Returns
trueif at least one element in a collection is truthy,falseotherwise.Use
Array.some(Boolean)to test if any elements in the collection are truthy.const any = arr => arr.some(Boolean); -any([0, 0, 1, 0]); // true -anyBy
Returns
trueif the provided predicate function returnstruefor at least one element in a collection,falseotherwise.Use
Array.some()to test if any elements in the collection returntruebased onfn.const anyBy = (arr, fn) => arr.some(fn); -anyBy([0, 1, 2, 0], x => x >= 2); // true +Array
all
Returns
trueif the provided predicate function returnstruefor all elements in a collection,falseotherwise.Use
Array.every()to test if all elements in the collection returntruebased onfn. Omit the second argument,fn, to useBooleanas a default.const all = (arr, fn = Boolean) => arr.every(fn); +all([4, 2, 3], x => x > 1); // true +all([1, 2, 3]); // true +any
Returns
trueif the provided predicate function returnstruefor at least one element in a collection,falseotherwise.Use
Array.some()to test if any elements in the collection returntruebased onfn. Omit the second argument,fn, to useBooleanas a default.const any = (arr, fn = Boolean) => arr.some(fn); +any([0, 1, 2, 0], x => x >= 2); // true +any([0, 0, 1, 0]); // truebifurcate
Splits values into two groups. If an element in
filteris truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.Use
Array.reduce()andArray.push()to add elements to groups, based onfilter.const bifurcate = (arr, filter) => arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ] @@ -297,10 +295,9 @@ Object.assigminN
Returns the
nminimum elements from the provided array. Ifnis greater than or equal to the provided array's length, then return the original array(sorted in ascending order).Use
Array.sort()combined with the spread operator (...) to create a shallow clone of the array and sort it in ascending order. UseArray.slice()to get the specified number of elements. Omit the second argument,n, to get a one-element array.const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);minN([1, 2, 3]); // [1] minN([1, 2, 3], 2); // [1,2] -none
Returns
trueif no elements in a collection are truthy,falseotherwise.Use
!Array.some(Boolean)to test if any elements in the collection are truthy.const none = arr => !arr.some(Boolean); -none([0, 0, 0]); // true -noneBy
Returns
trueif the provided predicate function returnsfalsefor all elements in a collection,falseotherwise.Use
Array.some()to test if any elements in the collection returntruebased onfn.const noneBy = (arr, fn) => !arr.some(fn); -noneBy([0, 1, 3, 0], x => x == 2); // true +none
Returns
trueif the provided predicate function returnsfalsefor all elements in a collection,falseotherwise.Use
Array.some()to test if any elements in the collection returntruebased onfn. Omit the second argument,fn, to useBooleanas a default.const none = (arr, fn = Boolean) => !arr.some(fn); +none([0, 1, 3, 0], x => x == 2); // true +none([0, 0, 0]); // truenthElement
Returns the nth element of an array.
Use
Array.slice()to get an array containing the nth element at the first place. If the index is out of bounds, return[]. Omit the second argument,n, to get the first element of the array.const nthElement = (arr, n = 0) => (n > 0 ? arr.slice(n, n + 1) : arr.slice(n))[0];nthElement(['a', 'b', 'c'], 1); // 'b' nthElement(['a', 'b', 'b'], -3); // 'a' diff --git a/package.json b/package.json index 094ca7ffd..4dd3113d2 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "name": "30-seconds-of-code", "description": "A collection of useful JavaScript snippets.", - "version": "0.0.1", + "version": "0.0.2", "main": "dist/_30s.js", "module": "dist/_30s.esm.js", "scripts": { 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/arrayToHtmlList/arrayToHtmlList.test.js b/test/arrayToHtmlList/arrayToHtmlList.test.js index 1f8885778..7cb8f4582 100644 --- a/test/arrayToHtmlList/arrayToHtmlList.test.js +++ b/test/arrayToHtmlList/arrayToHtmlList.test.js @@ -5,9 +5,10 @@ test('Testing arrayToHtmlList', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof arrayToHtmlList === 'function', 'arrayToHtmlList is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(arrayToHtmlList(args..), 'Expected'); //t.equal(arrayToHtmlList(args..), 'Expected'); //t.false(arrayToHtmlList(args..), 'Expected'); //t.throws(arrayToHtmlList(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/chainAsync/chainAsync.test.js b/test/chainAsync/chainAsync.test.js index d013df52f..a1e6edd06 100644 --- a/test/chainAsync/chainAsync.test.js +++ b/test/chainAsync/chainAsync.test.js @@ -5,22 +5,19 @@ test('Testing chainAsync', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof chainAsync === 'function', 'chainAsync is a Function'); - //t.deepEqual(chainAsync(args..), 'Expected'); - // chainAsync([ - // next => { - // next(); - // }, - // next => { - // (() =>{ - // next() - // })(); - // }, - // next => { - // t.pass("Calls all functions in an array"); - // next(); - // } - // ]); - // + chainAsync([ + next => { + next(); + }, + next => { + (() => { + next(); + })(); + }, + next => { + t.pass("Calls all functions in an array"); + } + ]); // // Ensure we wait for the 2nd assertion to be made // t.plan(2); diff --git a/test/createElement/createElement.test.js b/test/createElement/createElement.test.js index f773ea672..6923ec245 100644 --- a/test/createElement/createElement.test.js +++ b/test/createElement/createElement.test.js @@ -5,9 +5,10 @@ test('Testing createElement', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof createElement === 'function', 'createElement is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(createElement(args..), 'Expected'); //t.equal(createElement(args..), 'Expected'); //t.false(createElement(args..), 'Expected'); //t.throws(createElement(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/createEventHub/createEventHub.test.js b/test/createEventHub/createEventHub.test.js index 759c461b3..101d07aef 100644 --- a/test/createEventHub/createEventHub.test.js +++ b/test/createEventHub/createEventHub.test.js @@ -5,9 +5,10 @@ test('Testing createEventHub', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof createEventHub === 'function', 'createEventHub is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(createEventHub(args..), 'Expected'); //t.equal(createEventHub(args..), 'Expected'); //t.false(createEventHub(args..), 'Expected'); //t.throws(createEventHub(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/currentURL/currentURL.test.js b/test/currentURL/currentURL.test.js index e7dba8ee4..e190ad429 100644 --- a/test/currentURL/currentURL.test.js +++ b/test/currentURL/currentURL.test.js @@ -5,9 +5,10 @@ test('Testing currentURL', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof currentURL === 'function', 'currentURL is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(currentURL(args..), 'Expected'); //t.equal(currentURL(args..), 'Expected'); //t.false(currentURL(args..), 'Expected'); //t.throws(currentURL(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/debounce/debounce.test.js b/test/debounce/debounce.test.js index f1a35323c..867aac93a 100644 --- a/test/debounce/debounce.test.js +++ b/test/debounce/debounce.test.js @@ -5,9 +5,10 @@ test('Testing debounce', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof debounce === 'function', 'debounce is a Function'); + debounce(() => {t.pass('Works as expected');}, 250); //t.deepEqual(debounce(args..), 'Expected'); //t.equal(debounce(args..), 'Expected'); //t.false(debounce(args..), 'Expected'); //t.throws(debounce(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/defaults/defaults.test.js b/test/defaults/defaults.test.js index ab1afa29e..b3c519f9d 100644 --- a/test/defaults/defaults.test.js +++ b/test/defaults/defaults.test.js @@ -5,9 +5,10 @@ test('Testing defaults', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof defaults === 'function', 'defaults is a Function'); + t.deepEqual(defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }), { a: 1, b: 2 }, 'Assigns default values for undefined properties'); //t.deepEqual(defaults(args..), 'Expected'); //t.equal(defaults(args..), 'Expected'); //t.false(defaults(args..), 'Expected'); //t.throws(defaults(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/defer/defer.test.js b/test/defer/defer.test.js index faa5731c9..23e125b90 100644 --- a/test/defer/defer.test.js +++ b/test/defer/defer.test.js @@ -5,9 +5,10 @@ test('Testing defer', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof defer === 'function', 'defer is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(defer(args..), 'Expected'); //t.equal(defer(args..), 'Expected'); //t.false(defer(args..), 'Expected'); //t.throws(defer(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/delay/delay.test.js b/test/delay/delay.test.js index 544f8632d..8404b3bcb 100644 --- a/test/delay/delay.test.js +++ b/test/delay/delay.test.js @@ -5,9 +5,16 @@ test('Testing delay', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof delay === 'function', 'delay is a Function'); + delay( + function(text) { + t.equals(text, 'test', 'Works as expecting, passing arguments properly'); + }, + 1000, + 'test' + ); //t.deepEqual(delay(args..), 'Expected'); //t.equal(delay(args..), 'Expected'); //t.false(delay(args..), 'Expected'); //t.throws(delay(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/getScrollPosition/getScrollPosition.test.js b/test/getScrollPosition/getScrollPosition.test.js index ded20c020..9f7fd14d7 100644 --- a/test/getScrollPosition/getScrollPosition.test.js +++ b/test/getScrollPosition/getScrollPosition.test.js @@ -5,9 +5,10 @@ test('Testing getScrollPosition', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof getScrollPosition === 'function', 'getScrollPosition is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(getScrollPosition(args..), 'Expected'); //t.equal(getScrollPosition(args..), 'Expected'); //t.false(getScrollPosition(args..), 'Expected'); //t.throws(getScrollPosition(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/getStyle/getStyle.test.js b/test/getStyle/getStyle.test.js index 11c2c9244..23bac0147 100644 --- a/test/getStyle/getStyle.test.js +++ b/test/getStyle/getStyle.test.js @@ -5,9 +5,10 @@ test('Testing getStyle', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof getStyle === 'function', 'getStyle is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(getStyle(args..), 'Expected'); //t.equal(getStyle(args..), 'Expected'); //t.false(getStyle(args..), 'Expected'); //t.throws(getStyle(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/hasFlags/hasFlags.test.js b/test/hasFlags/hasFlags.test.js index 0245051be..be0d4c301 100644 --- a/test/hasFlags/hasFlags.test.js +++ b/test/hasFlags/hasFlags.test.js @@ -5,9 +5,10 @@ test('Testing hasFlags', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof hasFlags === 'function', 'hasFlags is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(hasFlags(args..), 'Expected'); //t.equal(hasFlags(args..), 'Expected'); //t.false(hasFlags(args..), 'Expected'); //t.throws(hasFlags(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/hashBrowser/hashBrowser.test.js b/test/hashBrowser/hashBrowser.test.js index d01cafc5b..5464dd95d 100644 --- a/test/hashBrowser/hashBrowser.test.js +++ b/test/hashBrowser/hashBrowser.test.js @@ -5,9 +5,10 @@ test('Testing hashBrowser', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof hashBrowser === 'function', 'hashBrowser is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(hashBrowser(args..), 'Expected'); //t.equal(hashBrowser(args..), 'Expected'); //t.false(hashBrowser(args..), 'Expected'); //t.throws(hashBrowser(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/hide/hide.test.js b/test/hide/hide.test.js index d93d3fa74..af1971858 100644 --- a/test/hide/hide.test.js +++ b/test/hide/hide.test.js @@ -5,9 +5,10 @@ test('Testing hide', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof hide === 'function', 'hide is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(hide(args..), 'Expected'); //t.equal(hide(args..), 'Expected'); //t.false(hide(args..), 'Expected'); //t.throws(hide(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/mostPerformant/mostPerformant.test.js b/test/mostPerformant/mostPerformant.test.js index ab09a13b0..95a560f91 100644 --- a/test/mostPerformant/mostPerformant.test.js +++ b/test/mostPerformant/mostPerformant.test.js @@ -5,9 +5,10 @@ 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(); -}); \ No newline at end of file +}); 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/off/off.test.js b/test/off/off.test.js index 030e7797a..8a3eca663 100644 --- a/test/off/off.test.js +++ b/test/off/off.test.js @@ -5,9 +5,10 @@ test('Testing off', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof off === 'function', 'off is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(off(args..), 'Expected'); //t.equal(off(args..), 'Expected'); //t.false(off(args..), 'Expected'); //t.throws(off(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/on/on.test.js b/test/on/on.test.js index 5bfa58a76..f14e85ad0 100644 --- a/test/on/on.test.js +++ b/test/on/on.test.js @@ -5,9 +5,10 @@ test('Testing on', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof on === 'function', 'on is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(on(args..), 'Expected'); //t.equal(on(args..), 'Expected'); //t.false(on(args..), 'Expected'); //t.throws(on(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/onUserInputChange/onUserInputChange.test.js b/test/onUserInputChange/onUserInputChange.test.js index c4c181806..bbc726d63 100644 --- a/test/onUserInputChange/onUserInputChange.test.js +++ b/test/onUserInputChange/onUserInputChange.test.js @@ -5,9 +5,10 @@ test('Testing onUserInputChange', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof onUserInputChange === 'function', 'onUserInputChange is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(onUserInputChange(args..), 'Expected'); //t.equal(onUserInputChange(args..), 'Expected'); //t.false(onUserInputChange(args..), 'Expected'); //t.throws(onUserInputChange(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/once/once.test.js b/test/once/once.test.js index 6d457fe01..89aba3872 100644 --- a/test/once/once.test.js +++ b/test/once/once.test.js @@ -5,9 +5,10 @@ test('Testing once', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof once === 'function', 'once is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(once(args..), 'Expected'); //t.equal(once(args..), 'Expected'); //t.false(once(args..), 'Expected'); //t.throws(once(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/randomHexColorCode/randomHexColorCode.test.js b/test/randomHexColorCode/randomHexColorCode.test.js index d604bc77e..7d9946955 100644 --- a/test/randomHexColorCode/randomHexColorCode.test.js +++ b/test/randomHexColorCode/randomHexColorCode.test.js @@ -8,8 +8,8 @@ test('Testing randomHexColorCode', (t) => { //t.deepEqual(randomHexColorCode(args..), 'Expected'); t.equal(randomHexColorCode().length, 7); t.true(randomHexColorCode().startsWith('#'),'The color code starts with "#"'); - t.true(randomHexColorCode().slice(1).match(/[^0123456789abcdef]/i) === null) + t.true(randomHexColorCode().slice(1).match(/[^0123456789abcdef]/i) === null,'The color code contains only valid hex-digits'); //t.false(randomHexColorCode(args..), 'Expected'); //t.throws(randomHexColorCode(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/setStyle/setStyle.test.js b/test/setStyle/setStyle.test.js index 796ab1316..3c8e4aa94 100644 --- a/test/setStyle/setStyle.test.js +++ b/test/setStyle/setStyle.test.js @@ -5,9 +5,10 @@ test('Testing setStyle', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof setStyle === 'function', 'setStyle is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(setStyle(args..), 'Expected'); //t.equal(setStyle(args..), 'Expected'); //t.false(setStyle(args..), 'Expected'); //t.throws(setStyle(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/show/show.test.js b/test/show/show.test.js index 06cf5e26e..859735338 100644 --- a/test/show/show.test.js +++ b/test/show/show.test.js @@ -5,9 +5,10 @@ test('Testing show', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof show === 'function', 'show is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(show(args..), 'Expected'); //t.equal(show(args..), 'Expected'); //t.false(show(args..), 'Expected'); //t.throws(show(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/sleep/sleep.test.js b/test/sleep/sleep.test.js index 8d5388924..57beb16e2 100644 --- a/test/sleep/sleep.test.js +++ b/test/sleep/sleep.test.js @@ -5,9 +5,13 @@ test('Testing sleep', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof sleep === 'function', 'sleep is a Function'); + async function sleepyWork() { + await sleep(1000); + t.pass('Works as expected'); + } //t.deepEqual(sleep(args..), 'Expected'); //t.equal(sleep(args..), 'Expected'); //t.false(sleep(args..), 'Expected'); //t.throws(sleep(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/testlog b/test/testlog index 986bc9003..a68b12cfd 100644 --- a/test/testlog +++ b/test/testlog @@ -1,24 +1,20 @@ -Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) +Test log for: Fri Feb 16 2018 20:23:57 GMT+0000 (UTC) -> 30-seconds-of-code@0.0.1 test R:\github\30-seconds-of-code +> 30-seconds-of-code@0.0.2 test /home/travis/build/Chalarangelo/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 + ✔ 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 + ✔ Returns true with predicate function + ✔ Returns false with a predicate function Testing anagrams @@ -29,16 +25,12 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) 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 + ✔ 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 + ✔ Returns true with predicate function + ✔ Returns false with a predicate function Testing approximatelyEqual @@ -50,7 +42,8 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing arrayToHtmlList - √ arrayToHtmlList is a Function + ✔ arrayToHtmlList is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing ary @@ -71,18 +64,18 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing average - √ average is a Function - √ average(true) returns 0 - √ average(false) returns 1 - √ average(9, 1) returns 5 - √ average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 - √ average(1, 2, 3) returns 2 - √ average(null) returns 0 - √ average(1, 2, 3) returns NaN - √ average(String) returns NaN - √ average({ a: 123}) returns NaN - √ average([undefined, 0, string]) returns NaN - √ average([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run + ✔ average is a Function + ✔ average(true) returns 0 + ✔ average(false) returns 1 + ✔ average(9, 1) returns 5 + ✔ average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 + ✔ average(1, 2, 3) returns 2 + ✔ average(null) returns 0 + ✔ average(1, 2, 3) returns NaN + ✔ average(String) returns NaN + ✔ average({ a: 123}) returns NaN + ✔ average([undefined, 0, string]) returns NaN + ✔ average([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run Testing averageBy @@ -180,7 +173,8 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing chainAsync - √ chainAsync is a Function + ✔ chainAsync is a Function + ✔ Calls all functions in an array Testing chunk @@ -279,15 +273,18 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing createElement - √ createElement is a Function + ✔ createElement is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing createEventHub - √ createEventHub is a Function + ✔ createEventHub is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing currentURL - √ currentURL is a Function + ✔ currentURL is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing curry @@ -318,11 +315,13 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing defaults - √ defaults is a Function + ✔ defaults is a Function + ✔ Assigns default values for undefined properties Testing defer - √ defer is a Function + ✔ defer is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing degreesToRads @@ -576,11 +575,13 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing getScrollPosition - √ getScrollPosition is a Function + ✔ getScrollPosition is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing getStyle - √ getStyle is a Function + ✔ getStyle is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing getType @@ -609,11 +610,13 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing hasFlags - √ hasFlags is a Function + ✔ hasFlags is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing hashBrowser - √ hashBrowser is a Function + ✔ hashBrowser is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing hashNode @@ -640,7 +643,8 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing hide - √ hide is a Function + ✔ hide is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing howManyTimes @@ -1086,7 +1090,8 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing mostPerformant - √ mostPerformant is a Function + ✔ mostPerformant is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing negate @@ -1095,15 +1100,11 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) 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 + ✔ none is a Function + ✔ Returns true for arrays with no truthy values + ✔ Returns false for arrays with at least one truthy value + ✔ Returns true with a predicate function + ✔ Returns false with predicate function Testing nthArg @@ -1135,7 +1136,8 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing off - √ off is a Function + ✔ off is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing omit @@ -1149,15 +1151,18 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing on - √ on is a Function + ✔ on is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing once - √ once is a Function + ✔ onUserInputChange is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing onUserInputChange - √ onUserInputChange is a Function + ✔ once is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing orderBy @@ -1299,10 +1304,10 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing randomHexColorCode - √ randomHexColorCode is a Function - √ should be equal - √ The color code starts with "#" - √ should be truthy + ✔ randomHexColorCode is a Function + ✔ should be equal + ✔ The color code starts with "#" + ✔ The color code contains only valid hex-digits Testing randomIntArrayInRange @@ -1435,7 +1440,8 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing setStyle - √ setStyle is a Function + ✔ setStyle is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing shallowClone @@ -1445,7 +1451,8 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing show - √ show is a Function + ✔ show is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing shuffle @@ -1586,12 +1593,13 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing throttle - √ throttle is a Function + ✔ throttle is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing times - √ times is a Function - √ Runs a function the specified amount of times + ✔ timeTaken is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing timeTaken @@ -1656,18 +1664,8 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing toSafeInteger - √ toSafeInteger is a Function - √ Number(toSafeInteger(3.2)) is a number - √ Converts a value to a safe integer - √ toSafeInteger('4.2') returns 4 - √ toSafeInteger(4.6) returns 5 - √ toSafeInteger([]) returns 0 - √ isNaN(toSafeInteger([1.5, 3124])) is true - √ isNaN(toSafeInteger('string')) is true - √ isNaN(toSafeInteger({})) is true - √ isNaN(toSafeInteger()) is true - √ toSafeInteger(Infinity) returns 9007199254740991 - √ toSafeInteger(3.2) takes less than 2s to run + ✔ toggleClass is a Function + ✔ Tested by @chalarangelo on 16/02/2018 Testing toSnakeCase @@ -1890,16 +1888,17 @@ Test log for: Sat Feb 17 2018 21:51:17 GMT+0530 (India Standard Time) Testing zipWith - √ zipWith is a Function - √ Runs the function provided - √ Runs promises in series - √ Sends a GET request - √ Works with multiple promises - √ Sends a POST request + ✔ zipWith is a Function + ✔ Sends a GET request + ✔ Runs the function provided + ✔ Sends a POST request + ✔ Runs promises in series + ✔ Works as expecting, passing arguments properly + ✔ Works with multiple promises - total: 951 - passing: 951 - duration: 5.6s + total: 970 + passing: 970 + duration: 2.5s diff --git a/test/throttle/throttle.test.js b/test/throttle/throttle.test.js index 4de75afdb..fcd88a603 100644 --- a/test/throttle/throttle.test.js +++ b/test/throttle/throttle.test.js @@ -5,9 +5,10 @@ test('Testing throttle', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof throttle === 'function', 'throttle is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(throttle(args..), 'Expected'); //t.equal(throttle(args..), 'Expected'); //t.false(throttle(args..), 'Expected'); //t.throws(throttle(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/timeTaken/timeTaken.test.js b/test/timeTaken/timeTaken.test.js index 45d8aa0eb..fd72e9d13 100644 --- a/test/timeTaken/timeTaken.test.js +++ b/test/timeTaken/timeTaken.test.js @@ -5,9 +5,10 @@ test('Testing timeTaken', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof timeTaken === 'function', 'timeTaken is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(timeTaken(args..), 'Expected'); //t.equal(timeTaken(args..), 'Expected'); //t.false(timeTaken(args..), 'Expected'); //t.throws(timeTaken(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/toggleClass/toggleClass.test.js b/test/toggleClass/toggleClass.test.js index f7424a31d..f0bbe14d6 100644 --- a/test/toggleClass/toggleClass.test.js +++ b/test/toggleClass/toggleClass.test.js @@ -5,9 +5,10 @@ test('Testing toggleClass', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof toggleClass === 'function', 'toggleClass is a Function'); + t.pass('Tested by @chalarangelo on 16/02/2018'); //t.deepEqual(toggleClass(args..), 'Expected'); //t.equal(toggleClass(args..), 'Expected'); //t.false(toggleClass(args..), 'Expected'); //t.throws(toggleClass(args..), 'Expected'); t.end(); -}); \ No newline at end of file +});