Merge branch 'master' into any-all-none
This commit is contained in:
187
README.md
187
README.md
@ -98,6 +98,8 @@ average(1, 2, 3);
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
|
||||
* [`bifurcate`](#bifurcate)
|
||||
* [`bifurcateBy`](#bifurcateby)
|
||||
* [`chunk`](#chunk)
|
||||
* [`compact`](#compact)
|
||||
* [`countBy`](#countby)
|
||||
@ -246,6 +248,7 @@ average(1, 2, 3);
|
||||
* [`sleep`](#sleep)
|
||||
* [`throttle`](#throttle)
|
||||
* [`times`](#times)
|
||||
* [`uncurry`](#uncurry)
|
||||
* [`unfold`](#unfold)
|
||||
|
||||
</details>
|
||||
@ -255,9 +258,12 @@ average(1, 2, 3);
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
|
||||
* [`approximatelyEqual`](#approximatelyequal)
|
||||
* [`average`](#average)
|
||||
* [`averageBy`](#averageby)
|
||||
* [`binomialCoefficient`](#binomialcoefficient)
|
||||
* [`clampNumber`](#clampnumber)
|
||||
* [`degreesToRads`](#degreestorads)
|
||||
* [`digitize`](#digitize)
|
||||
* [`distance`](#distance)
|
||||
* [`elo`](#elo-)
|
||||
@ -278,6 +284,7 @@ average(1, 2, 3);
|
||||
* [`percentile`](#percentile)
|
||||
* [`powerset`](#powerset)
|
||||
* [`primes`](#primes)
|
||||
* [`radsToDegrees`](#radstodegrees)
|
||||
* [`randomIntArrayInRange`](#randomintarrayinrange)
|
||||
* [`randomIntegerInRange`](#randomintegerinrange)
|
||||
* [`randomNumberInRange`](#randomnumberinrange)
|
||||
@ -760,6 +767,52 @@ const unary = fn => val => fn(val);
|
||||
---
|
||||
## 📚 Array
|
||||
|
||||
### bifurcate
|
||||
|
||||
Splits values into two groups. If an element in `filter` is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.
|
||||
|
||||
Use `Array.reduce()` and `Array.push()` to add elements to groups, based on `filter`.
|
||||
|
||||
```js
|
||||
const bifurcate = (arr, filter) =>
|
||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### bifurcateBy
|
||||
|
||||
Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group.
|
||||
|
||||
Use `Array.reduce()` and `Array.push()` to add elements to groups, based on the value returned by `fn` for each element.
|
||||
|
||||
```js
|
||||
const bifurcateBy = (arr, fn) =>
|
||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### chunk
|
||||
|
||||
Chunks an array into smaller arrays of a specified size.
|
||||
@ -4199,6 +4252,38 @@ console.log(output); // 01234
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### uncurry
|
||||
|
||||
Uncurries a function up to depth `n`.
|
||||
|
||||
Return a variadic function.
|
||||
Use `Array.reduce()` on the provided arguments to call each subsequent curry level of the function.
|
||||
If the `length` of the provided arguments is less than `n` throw an error.
|
||||
Otherwise, call `fn` with the proper amount of arguments, using `Array.slice(0, n)`.
|
||||
Omit the second argument, `n`, to uncurry up to depth `1`.
|
||||
|
||||
```js
|
||||
const uncurry = (fn, n = 1) => (...args) => {
|
||||
const next = acc => args => args.reduce((x, y) => x(y), acc);
|
||||
if (n > args.length) throw new RangeError('Arguments too few!');
|
||||
return next(fn)(args.slice(0, n));
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
const add = x => y => z => x + y + z;
|
||||
const uncurriedAdd = uncurry(add, 3);
|
||||
uncurriedAdd(1, 2, 3); // 6
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### unfold
|
||||
|
||||
Builds an array, using an iterator function and an initial seed value.
|
||||
@ -4230,6 +4315,29 @@ unfold(f, 10); // [-10, -20, -30, -40, -50]
|
||||
---
|
||||
## ➗ Math
|
||||
|
||||
### approximatelyEqual
|
||||
|
||||
Checks if two numbers are approximately equal to each other.
|
||||
|
||||
Use `Math.abs()` to compare the absolute difference of the two values to `epsilon`.
|
||||
Omit the third parameter, `epsilon`, to use a default value of `0.001`.
|
||||
|
||||
```js
|
||||
const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
approximatelyEqual(Math.PI / 2.0, 1.5708); // true
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### average
|
||||
|
||||
Returns the average of two or more numbers.
|
||||
@ -4278,6 +4386,41 @@ averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 5
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### binomialCoefficient
|
||||
|
||||
Evaluates the binomial coefficient of two integers `n` and `k`.
|
||||
|
||||
Use `Number.isNaN()` to check if any of the two values is `NaN`.
|
||||
Check if `k` is less than `0`, greater than or equal to `n`, equal to `1` or `n - 1` and return the appropriate result.
|
||||
Check if `n - k` is less than `k` and switch their values accordingly.
|
||||
Loop from `2` through `k` and calculate the binomial coefficient.
|
||||
Use `Math.round()` to account for rounding errors in the calculation.
|
||||
|
||||
```js
|
||||
const binomialCoefficient = (n, k) => {
|
||||
if (Number.isNaN(n) || Number.isNaN(k)) return NaN;
|
||||
if (k < 0 || k > n) return 0;
|
||||
if (k === 0 || k === n) return 1;
|
||||
if (k === 1 || k === n - 1) return n;
|
||||
if (n - k < k) k = n - k;
|
||||
let res = n;
|
||||
for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;
|
||||
return Math.round(res);
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
binomialCoefficient(8, 2); // 28
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### clampNumber
|
||||
|
||||
Clamps `num` within the inclusive range specified by the boundary values `a` and `b`.
|
||||
@ -4302,6 +4445,28 @@ clampNumber(1, -1, -5); // -1
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### degreesToRads
|
||||
|
||||
Converts an angle from degrees to radians.
|
||||
|
||||
Use `Math.PI` and the degree to radian formula to convert the angle from degrees to radians.
|
||||
|
||||
```js
|
||||
const degreesToRads = deg => deg * Math.PI / 180.0;
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
degreesToRads(90.0); // ~1.5708
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### digitize
|
||||
|
||||
Converts a number to an array of digits.
|
||||
@ -4850,6 +5015,28 @@ primes(10); // [2,3,5,7]
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### radsToDegrees
|
||||
|
||||
Converts an angle from radians to degrees.
|
||||
|
||||
Use `Math.PI` and the radian to degree formula to convert the angle from radians to degrees.
|
||||
|
||||
```js
|
||||
const radsToDegrees = rad => rad * 180.0 / Math.PI;
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
radsToDegrees(Math.PI / 2); // 90
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### randomIntArrayInRange
|
||||
|
||||
Returns an array of n random integers in the specified range.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -10,5 +10,5 @@ const functionName = arguments =>
|
||||
```
|
||||
|
||||
```js
|
||||
functionName('sampleInput') // 'sampleOutput'
|
||||
functionName('sampleInput'); // 'sampleOutput'
|
||||
```
|
||||
|
||||
14
snippets/approximatelyEqual.md
Normal file
14
snippets/approximatelyEqual.md
Normal file
@ -0,0 +1,14 @@
|
||||
### approximatelyEqual
|
||||
|
||||
Checks if two numbers are approximately equal to each other.
|
||||
|
||||
Use `Math.abs()` to compare the absolute difference of the two values to `epsilon`.
|
||||
Omit the third parameter, `epsilon`, to use a default value of `0.001`.
|
||||
|
||||
```js
|
||||
const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
|
||||
```
|
||||
|
||||
```js
|
||||
approximatelyEqual(Math.PI / 2.0, 1.5708); // true
|
||||
```
|
||||
14
snippets/bifurcate.md
Normal file
14
snippets/bifurcate.md
Normal file
@ -0,0 +1,14 @@
|
||||
### bifurcate
|
||||
|
||||
Splits values into two groups. If an element in `filter` is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.
|
||||
|
||||
Use `Array.reduce()` and `Array.push()` to add elements to groups, based on `filter`.
|
||||
|
||||
```js
|
||||
const bifurcate = (arr, filter) =>
|
||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
|
||||
```
|
||||
|
||||
```js
|
||||
bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||
```
|
||||
14
snippets/bifurcateBy.md
Normal file
14
snippets/bifurcateBy.md
Normal file
@ -0,0 +1,14 @@
|
||||
### bifurcateBy
|
||||
|
||||
Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group.
|
||||
|
||||
Use `Array.reduce()` and `Array.push()` to add elements to groups, based on the value returned by `fn` for each element.
|
||||
|
||||
```js
|
||||
const bifurcateBy = (arr, fn) =>
|
||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
|
||||
```
|
||||
|
||||
```js
|
||||
bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||
```
|
||||
26
snippets/binomialCoefficient.md
Normal file
26
snippets/binomialCoefficient.md
Normal file
@ -0,0 +1,26 @@
|
||||
### binomialCoefficient
|
||||
|
||||
Evaluates the binomial coefficient of two integers `n` and `k`.
|
||||
|
||||
Use `Number.isNaN()` to check if any of the two values is `NaN`.
|
||||
Check if `k` is less than `0`, greater than or equal to `n`, equal to `1` or `n - 1` and return the appropriate result.
|
||||
Check if `n - k` is less than `k` and switch their values accordingly.
|
||||
Loop from `2` through `k` and calculate the binomial coefficient.
|
||||
Use `Math.round()` to account for rounding errors in the calculation.
|
||||
|
||||
```js
|
||||
const binomialCoefficient = (n, k) => {
|
||||
if (Number.isNaN(n) || Number.isNaN(k)) return NaN;
|
||||
if (k < 0 || k > n) return 0;
|
||||
if (k === 0 || k === n) return 1;
|
||||
if (k === 1 || k === n - 1) return n;
|
||||
if (n - k < k) k = n - k;
|
||||
let res = n;
|
||||
for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;
|
||||
return Math.round(res);
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
binomialCoefficient(8, 2); // 28
|
||||
```
|
||||
13
snippets/degreesToRads.md
Normal file
13
snippets/degreesToRads.md
Normal file
@ -0,0 +1,13 @@
|
||||
### degreesToRads
|
||||
|
||||
Converts an angle from degrees to radians.
|
||||
|
||||
Use `Math.PI` and the degree to radian formula to convert the angle from degrees to radians.
|
||||
|
||||
```js
|
||||
const degreesToRads = deg => deg * Math.PI / 180.0;
|
||||
```
|
||||
|
||||
```js
|
||||
degreesToRads(90.0); // ~1.5708
|
||||
```
|
||||
13
snippets/radsToDegrees.md
Normal file
13
snippets/radsToDegrees.md
Normal file
@ -0,0 +1,13 @@
|
||||
### radsToDegrees
|
||||
|
||||
Converts an angle from radians to degrees.
|
||||
|
||||
Use `Math.PI` and the radian to degree formula to convert the angle from radians to degrees.
|
||||
|
||||
```js
|
||||
const radsToDegrees = rad => rad * 180.0 / Math.PI;
|
||||
```
|
||||
|
||||
```js
|
||||
radsToDegrees(Math.PI / 2); // 90
|
||||
```
|
||||
23
snippets/uncurry.md
Normal file
23
snippets/uncurry.md
Normal file
@ -0,0 +1,23 @@
|
||||
### uncurry
|
||||
|
||||
Uncurries a function up to depth `n`.
|
||||
|
||||
Return a variadic function.
|
||||
Use `Array.reduce()` on the provided arguments to call each subsequent curry level of the function.
|
||||
If the `length` of the provided arguments is less than `n` throw an error.
|
||||
Otherwise, call `fn` with the proper amount of arguments, using `Array.slice(0, n)`.
|
||||
Omit the second argument, `n`, to uncurry up to depth `1`.
|
||||
|
||||
```js
|
||||
const uncurry = (fn, n = 1) => (...args) => {
|
||||
const next = acc => args => args.reduce((x, y) => x(y), acc);
|
||||
if (n > args.length) throw new RangeError('Arguments too few!');
|
||||
return next(fn)(args.slice(0, n));
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
const add = x => y => z => x + y + z;
|
||||
const uncurriedAdd = uncurry(add, 3);
|
||||
uncurriedAdd(1, 2, 3); // 6
|
||||
```
|
||||
@ -3,15 +3,19 @@ allBy:array,function
|
||||
anagrams:string,recursion
|
||||
any:array
|
||||
anyBy:array,function
|
||||
approximatelyEqual:math
|
||||
arrayToHtmlList:browser,array
|
||||
ary:adapter,function
|
||||
atob:node,string,utility
|
||||
attempt:function
|
||||
average:math,array
|
||||
averageBy:math,array,function
|
||||
bifurcate:array
|
||||
bifurcateBy:array,function
|
||||
bind:function,object
|
||||
bindAll:object,function
|
||||
bindKey:function,object
|
||||
binomialCoefficient:math
|
||||
bottomVisible:browser
|
||||
btoa:node,string,utility
|
||||
byteSize:string
|
||||
@ -44,6 +48,7 @@ deepClone:object,recursion
|
||||
deepFlatten:array,recursion
|
||||
defaults:object
|
||||
defer:function
|
||||
degreesToRads:math
|
||||
delay:function
|
||||
detectDeviceType:browser
|
||||
difference:array,math
|
||||
@ -193,6 +198,7 @@ pull:array
|
||||
pullAtIndex:array
|
||||
pullAtValue:array
|
||||
pullBy:array,function,advanced
|
||||
radsToDegrees:math
|
||||
randomHexColorCode:utility,random
|
||||
randomIntArrayInRange:math,utility,random
|
||||
randomIntegerInRange:math,utility,random
|
||||
@ -258,6 +264,7 @@ transform:object,array
|
||||
truncateString:string
|
||||
truthCheckCollection:object,logic,array
|
||||
unary:adapter,function
|
||||
uncurry:function
|
||||
unescapeHTML:string,browser
|
||||
unflattenObject:object,advanced
|
||||
unfold:function,array
|
||||
|
||||
2
test/approximatelyEqual/approximatelyEqual.js
Normal file
2
test/approximatelyEqual/approximatelyEqual.js
Normal file
@ -0,0 +1,2 @@
|
||||
const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
|
||||
module.exports = approximatelyEqual;
|
||||
17
test/approximatelyEqual/approximatelyEqual.test.js
Normal file
17
test/approximatelyEqual/approximatelyEqual.test.js
Normal file
@ -0,0 +1,17 @@
|
||||
const test = require('tape');
|
||||
const approximatelyEqual = require('./approximatelyEqual.js');
|
||||
|
||||
test('Testing approximatelyEqual', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof approximatelyEqual === 'function', 'approximatelyEqual is a Function');
|
||||
t.true(approximatelyEqual(Math.PI / 2.0 , 1.5708), 'Works for PI / 2');
|
||||
t.true(approximatelyEqual(0.1 + 0.2, 0.3), 'Works for 0.1 + 0.2 === 0.3');
|
||||
t.true(approximatelyEqual(0.5, 0.5), 'Works for exactly equal values');
|
||||
t.true(approximatelyEqual(0.501, 0.5, 0.1), 'Works for a custom epsilon');
|
||||
//t.deepEqual(approximatelyEqual(args..), 'Expected');
|
||||
//t.equal(approximatelyEqual(args..), 'Expected');
|
||||
//t.false(approximatelyEqual(args..), 'Expected');
|
||||
//t.throws(approximatelyEqual(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
3
test/bifurcate/bifurcate.js
Normal file
3
test/bifurcate/bifurcate.js
Normal file
@ -0,0 +1,3 @@
|
||||
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();
|
||||
});
|
||||
3
test/bifurcateBy/bifurcateBy.js
Normal file
3
test/bifurcateBy/bifurcateBy.js
Normal file
@ -0,0 +1,3 @@
|
||||
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();
|
||||
});
|
||||
11
test/binomialCoefficient/binomialCoefficient.js
Normal file
11
test/binomialCoefficient/binomialCoefficient.js
Normal file
@ -0,0 +1,11 @@
|
||||
const binomialCoefficient = (n, k) => {
|
||||
if (Number.isNaN(n) || Number.isNaN(k)) return NaN;
|
||||
if (k < 0 || k > n) return 0;
|
||||
if (k === 0 || k === n) return 1;
|
||||
if (k === 1 || k === n - 1) return n;
|
||||
if (n - k < k) k = n - k;
|
||||
let res = n;
|
||||
for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;
|
||||
return Math.round(res);
|
||||
};
|
||||
module.exports = binomialCoefficient;
|
||||
18
test/binomialCoefficient/binomialCoefficient.test.js
Normal file
18
test/binomialCoefficient/binomialCoefficient.test.js
Normal file
@ -0,0 +1,18 @@
|
||||
const test = require('tape');
|
||||
const binomialCoefficient = require('./binomialCoefficient.js');
|
||||
|
||||
test('Testing binomialCoefficient', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof binomialCoefficient === 'function', 'binomialCoefficient is a Function');
|
||||
t.equal(binomialCoefficient(8, 2), 28, 'Returns the appropriate value');
|
||||
t.equal(binomialCoefficient(0, 0), 1, 'Returns the appropriate value');
|
||||
t.equal(binomialCoefficient(5, 3), 10, 'Returns the appropriate value');
|
||||
t.true(Number.isNaN(binomialCoefficient(NaN, 3)), 'Returns NaN');
|
||||
t.true(Number.isNaN(binomialCoefficient(5, NaN)), 'Returns NaN');
|
||||
//t.deepEqual(binomialCoefficient(args..), 'Expected');
|
||||
//t.equal(binomialCoefficient(args..), 'Expected');
|
||||
//t.false(binomialCoefficient(args..), 'Expected');
|
||||
//t.throws(binomialCoefficient(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
2
test/degreesToRads/degreesToRads.js
Normal file
2
test/degreesToRads/degreesToRads.js
Normal file
@ -0,0 +1,2 @@
|
||||
const degreesToRads = deg => deg * Math.PI / 180.0;
|
||||
module.exports = degreesToRads;
|
||||
15
test/degreesToRads/degreesToRads.test.js
Normal file
15
test/degreesToRads/degreesToRads.test.js
Normal file
@ -0,0 +1,15 @@
|
||||
const test = require('tape');
|
||||
const degreesToRads = require('./degreesToRads.js');
|
||||
|
||||
test('Testing degreesToRads', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
const approxeq = (v1,v2, diff = 0.001) => Math.abs(v1 - v2) < diff; // Use to account for rounding errors
|
||||
t.true(typeof degreesToRads === 'function', 'degreesToRads is a Function');
|
||||
t.true(approxeq(degreesToRads(90.0), Math.PI / 2), 'Returns the appropriate value');
|
||||
//t.deepEqual(degreesToRads(args..), 'Expected');
|
||||
//t.equal(degreesToRads(args..), 'Expected');
|
||||
//t.false(degreesToRads(args..), 'Expected');
|
||||
//t.throws(degreesToRads(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
2
test/radsToDegrees/radsToDegrees.js
Normal file
2
test/radsToDegrees/radsToDegrees.js
Normal file
@ -0,0 +1,2 @@
|
||||
const radsToDegrees = rad => rad * 180.0 / Math.PI;
|
||||
module.exports = radsToDegrees;
|
||||
14
test/radsToDegrees/radsToDegrees.test.js
Normal file
14
test/radsToDegrees/radsToDegrees.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const test = require('tape');
|
||||
const radsToDegrees = require('./radsToDegrees.js');
|
||||
|
||||
test('Testing radsToDegrees', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof radsToDegrees === 'function', 'radsToDegrees is a Function');
|
||||
t.equal(radsToDegrees(Math.PI / 2), 90, 'Returns the appropriate value');
|
||||
//t.deepEqual(radsToDegrees(args..), 'Expected');
|
||||
//t.equal(radsToDegrees(args..), 'Expected');
|
||||
//t.false(radsToDegrees(args..), 'Expected');
|
||||
//t.throws(radsToDegrees(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
57
test/testlog
57
test/testlog
@ -1,9 +1,11 @@
|
||||
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
|
||||
@ -40,6 +42,21 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
√ 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
|
||||
√ Works for PI / 2
|
||||
√ Works for 0.1 + 0.2 === 0.3
|
||||
√ Works for exactly equal values
|
||||
√ Works for a custom epsilon
|
||||
|
||||
Testing arrayToHtmlList
|
||||
|
||||
√ arrayToHtmlList is a Function
|
||||
@ -82,6 +99,16 @@ Test log for: Wed Feb 14 2018 11:45:44 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
|
||||
@ -105,6 +132,15 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
√ bindKey is a Function
|
||||
√ Binds function to an object context
|
||||
|
||||
Testing binomialCoefficient
|
||||
|
||||
√ binomialCoefficient is a Function
|
||||
√ Returns the appropriate value
|
||||
√ Returns the appropriate value
|
||||
√ Returns the appropriate value
|
||||
√ Returns NaN
|
||||
√ Returns NaN
|
||||
|
||||
Testing bottomVisible
|
||||
|
||||
√ bottomVisible is a Function
|
||||
@ -297,6 +333,11 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
|
||||
√ defer is a Function
|
||||
|
||||
Testing degreesToRads
|
||||
|
||||
√ degreesToRads is a Function
|
||||
√ Returns the appropriate value
|
||||
|
||||
Testing delay
|
||||
|
||||
√ delay is a Function
|
||||
@ -1252,6 +1293,11 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
√ quickSort(undefined) throws an error
|
||||
√ quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run
|
||||
|
||||
Testing radsToDegrees
|
||||
|
||||
√ radsToDegrees is a Function
|
||||
√ Returns the appropriate value
|
||||
|
||||
Testing randomHexColorCode
|
||||
|
||||
√ randomHexColorCode is a Function
|
||||
@ -1655,6 +1701,13 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
√ unary is a Function
|
||||
√ Discards arguments after the first one
|
||||
|
||||
Testing uncurry
|
||||
|
||||
√ uncurry is a Function
|
||||
√ Works without a provided value for n
|
||||
√ Works without n = 2
|
||||
√ Works withoutn = 3
|
||||
|
||||
Testing unescapeHTML
|
||||
|
||||
√ unescapeHTML is a Function
|
||||
@ -1839,6 +1892,8 @@ Test log for: Wed Feb 14 2018 11:45:44 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
|
||||
@ -1846,6 +1901,6 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
|
||||
total: 924
|
||||
passing: 924
|
||||
duration: 2.4s
|
||||
duration: 2.5s
|
||||
|
||||
|
||||
|
||||
6
test/uncurry/uncurry.js
Normal file
6
test/uncurry/uncurry.js
Normal file
@ -0,0 +1,6 @@
|
||||
const uncurry = (fn, n = 1) => (...args) => {
|
||||
const next = acc => args => args.reduce((x, y) => x(y), acc);
|
||||
if (n > args.length) throw new RangeError('Arguments too few!');
|
||||
return next(fn)(args.slice(0, n));
|
||||
};
|
||||
module.exports = uncurry;
|
||||
20
test/uncurry/uncurry.test.js
Normal file
20
test/uncurry/uncurry.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
const test = require('tape');
|
||||
const uncurry = require('./uncurry.js');
|
||||
|
||||
test('Testing uncurry', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof uncurry === 'function', 'uncurry is a Function');
|
||||
const add = x => y => z => x + y + z;
|
||||
const add1 = uncurry(add);
|
||||
const add2 = uncurry(add, 2);
|
||||
const add3 = uncurry(add, 3);
|
||||
t.equal(add1(1)(2)(3), 6, 'Works without a provided value for n');
|
||||
t.equal(add2(1,2)(3), 6, 'Works without n = 2');
|
||||
t.equal(add3(1,2,3), 6, 'Works withoutn = 3');
|
||||
//t.deepEqual(uncurry(args..), 'Expected');
|
||||
//t.equal(uncurry(args..), 'Expected');
|
||||
//t.false(uncurry(args..), 'Expected');
|
||||
//t.throws(uncurry(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user