Merge branch 'master' of https://github.com/Chalarangelo/30-seconds-of-code
This commit is contained in:
366
README.md
366
README.md
@ -98,6 +98,12 @@ average(1, 2, 3);
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
|
||||
* [`all`](#all)
|
||||
* [`allBy`](#allby)
|
||||
* [`any`](#any)
|
||||
* [`anyBy`](#anyby)
|
||||
* [`bifurcate`](#bifurcate)
|
||||
* [`bifurcateBy`](#bifurcateby)
|
||||
* [`chunk`](#chunk)
|
||||
* [`compact`](#compact)
|
||||
* [`countBy`](#countby)
|
||||
@ -134,6 +140,8 @@ average(1, 2, 3);
|
||||
* [`mapObject`](#mapobject-)
|
||||
* [`maxN`](#maxn)
|
||||
* [`minN`](#minn)
|
||||
* [`none`](#none)
|
||||
* [`noneBy`](#noneby)
|
||||
* [`nthElement`](#nthelement)
|
||||
* [`partition`](#partition)
|
||||
* [`pull`](#pull)
|
||||
@ -246,6 +254,7 @@ average(1, 2, 3);
|
||||
* [`sleep`](#sleep)
|
||||
* [`throttle`](#throttle)
|
||||
* [`times`](#times)
|
||||
* [`uncurry`](#uncurry)
|
||||
* [`unfold`](#unfold)
|
||||
|
||||
</details>
|
||||
@ -255,9 +264,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 +290,7 @@ average(1, 2, 3);
|
||||
* [`percentile`](#percentile)
|
||||
* [`powerset`](#powerset)
|
||||
* [`primes`](#primes)
|
||||
* [`radsToDegrees`](#radstodegrees)
|
||||
* [`randomIntArrayInRange`](#randomintarrayinrange)
|
||||
* [`randomIntegerInRange`](#randomintegerinrange)
|
||||
* [`randomNumberInRange`](#randomnumberinrange)
|
||||
@ -421,6 +434,7 @@ average(1, 2, 3);
|
||||
* [`hexToRGB`](#hextorgb-)
|
||||
* [`httpGet`](#httpget)
|
||||
* [`httpPost`](#httppost)
|
||||
* [`mostPerformant`](#mostperformant)
|
||||
* [`nthArg`](#ntharg)
|
||||
* [`parseCookie`](#parsecookie)
|
||||
* [`prettyBytes`](#prettybytes)
|
||||
@ -760,6 +774,140 @@ const unary = fn => val => fn(val);
|
||||
---
|
||||
## 📚 Array
|
||||
|
||||
### 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);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
all([1, 2, 3]); // true
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### 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);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
allBy([4, 2, 3], x => x > 1); // true
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### 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);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
any([0, 0, 1, 0]); // true
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### 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);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
anyBy([0, 1, 2, 0], x => x >= 2); // true
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### 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.
|
||||
@ -1665,6 +1813,50 @@ minN([1, 2, 3], 2); // [1,2]
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### 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);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
none([0, 0, 0]); // true
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### 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);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
noneBy([0, 1, 3, 0], x => x == 2); // true
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### nthElement
|
||||
|
||||
Returns the nth element of an array.
|
||||
@ -4199,6 +4391,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 +4454,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 +4525,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 +4584,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 +5154,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.
|
||||
@ -7719,6 +8045,46 @@ Logs: {
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### mostPerformant
|
||||
|
||||
Returns the index of the function in an array of functions which executed the fastest.
|
||||
|
||||
Use `Array.map()` to generate an array where each value is the total time taken to execute the function after `iterations` times. Use the difference in `performance.now()` values before and after to get the total time in milliseconds to a high degree of accuracy.
|
||||
Use `Math.min()` to find the minimum execution time, and return the index of that shortest time which corresponds to the index of the most performant function.
|
||||
Omit the second argument, `iterations`, to use a default of 10,000 iterations. The more iterations, the more reliable the result but the longer it will take.
|
||||
|
||||
```js
|
||||
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));
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
mostPerformant([
|
||||
() => {
|
||||
// Loops through the entire array before returning `false`
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, '10'].every(el => typeof el === 'number');
|
||||
},
|
||||
() => {
|
||||
// Only needs to reach index `1` before returning false
|
||||
[1, '2', 3, 4, 5, 6, 7, 8, 9, 10].every(el => typeof el === 'number');
|
||||
}
|
||||
]); // 1
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### nthArg
|
||||
|
||||
Creates a function that gets the argument at index `n`. If `n` is negative, the nth argument from the end is returned.
|
||||
|
||||
220
dist/_30s.es5.js
vendored
220
dist/_30s.es5.js
vendored
File diff suppressed because one or more lines are too long
2
dist/_30s.es5.min.js
vendored
2
dist/_30s.es5.min.js
vendored
File diff suppressed because one or more lines are too long
64
dist/_30s.esm.js
vendored
64
dist/_30s.esm.js
vendored
@ -25,6 +25,10 @@ const UUIDGeneratorNode = () =>
|
||||
(c ^ (crypto$1.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
|
||||
);
|
||||
|
||||
const all = arr => arr.every(Boolean);
|
||||
|
||||
const allBy = (arr, fn) => arr.every(fn);
|
||||
|
||||
const anagrams = str => {
|
||||
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
||||
return str
|
||||
@ -36,6 +40,12 @@ const anagrams = str => {
|
||||
);
|
||||
};
|
||||
|
||||
const any = arr => arr.some(Boolean);
|
||||
|
||||
const anyBy = (arr, fn) => arr.some(fn);
|
||||
|
||||
const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
|
||||
|
||||
const arrayToHtmlList = (arr, listID) =>
|
||||
arr.map(item => (document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));
|
||||
|
||||
@ -57,6 +67,12 @@ const averageBy = (arr, fn) =>
|
||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
|
||||
arr.length;
|
||||
|
||||
const bifurcate = (arr, filter) =>
|
||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
|
||||
|
||||
const bifurcateBy = (arr, fn) =>
|
||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
|
||||
|
||||
const bind = (fn, context, ...args) =>
|
||||
function() {
|
||||
return fn.apply(context, args.concat(...arguments));
|
||||
@ -75,6 +91,17 @@ const bindKey = (context, fn, ...args) =>
|
||||
return context[fn].apply(context, args.concat(...arguments));
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
const bottomVisible = () =>
|
||||
document.documentElement.clientHeight + window.scrollY >=
|
||||
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
|
||||
@ -192,13 +219,11 @@ const currentURL = () => window.location.href;
|
||||
const curry = (fn, arity = fn.length, ...args) =>
|
||||
arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);
|
||||
|
||||
const debounce = (fn, wait = 0) => {
|
||||
let inDebounce;
|
||||
return function() {
|
||||
const context = this,
|
||||
args = arguments;
|
||||
clearTimeout(inDebounce);
|
||||
inDebounce = setTimeout(() => fn.apply(context, args), wait);
|
||||
const debounce = (fn, ms = 0) => {
|
||||
let timeoutId;
|
||||
return function(...args) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), ms);
|
||||
};
|
||||
};
|
||||
|
||||
@ -219,6 +244,8 @@ const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj
|
||||
|
||||
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
||||
|
||||
const degreesToRads = deg => deg * Math.PI / 180.0;
|
||||
|
||||
const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args);
|
||||
|
||||
const detectDeviceType = () =>
|
||||
@ -754,8 +781,21 @@ const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : v
|
||||
|
||||
const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
|
||||
|
||||
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));
|
||||
};
|
||||
|
||||
const negate = func => (...args) => !func(...args);
|
||||
|
||||
const none = arr => !arr.some(Boolean);
|
||||
|
||||
const noneBy = (arr, fn) => !arr.some(fn);
|
||||
|
||||
const nthArg = n => (...args) => args.slice(n)[0];
|
||||
|
||||
const nthElement = (arr, n = 0) => (n > 0 ? arr.slice(n, n + 1) : arr.slice(n))[0];
|
||||
@ -954,6 +994,8 @@ const pullBy = (arr, ...args) => {
|
||||
pulled.forEach(v => arr.push(v));
|
||||
};
|
||||
|
||||
const radsToDegrees = rad => rad * 180.0 / Math.PI;
|
||||
|
||||
const randomHexColorCode = () => {
|
||||
let n = (Math.random() * 0xfffff * 1000000).toString(16);
|
||||
return '#' + n.slice(0, 6);
|
||||
@ -1274,6 +1316,12 @@ const truthCheckCollection = (collection, pre) => collection.every(obj => obj[pr
|
||||
|
||||
const unary = fn => val => fn(val);
|
||||
|
||||
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));
|
||||
};
|
||||
|
||||
const unescapeHTML = str =>
|
||||
str.replace(
|
||||
/&|<|>|'|"/g,
|
||||
@ -1375,6 +1423,6 @@ const zipWith = (...arrays) => {
|
||||
return fn ? result.map(arr => fn(...arr)) : result;
|
||||
};
|
||||
|
||||
var imports = {JSONToFile,RGBToHex,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,anagrams,arrayToHtmlList,ary,atob,attempt,average,averageBy,bind,bindAll,bindKey,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compose,composeRight,converge,copyToClipboard,countBy,countOccurrences,createElement,createEventHub,currentURL,curry,debounce,decapitalize,deepClone,deepFlatten,defaults,defer,delay,detectDeviceType,difference,differenceBy,differenceWith,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterNonUnique,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,forOwn,forOwnRight,formatDuration,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,inRange,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isArrayLike,isBoolean,isDivisible,isEmpty,isEven,isFunction,isLowerCase,isNil,isNull,isNumber,isObject,isObjectLike,isPlainObject,isPrime,isPrimitive,isPromiseLike,isSorted,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,join,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapObject,mapValues,mask,matches,matchesWith,maxBy,maxN,median,memoize,merge,minBy,minN,negate,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,omit,omitBy,on,onUserInputChange,once,orderBy,over,overArgs,palindrome,parseCookie,partial,partialRight,partition,percentile,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,redirect,reduceSuccessive,reduceWhich,reducedFilter,remove,removeNonASCII,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,setStyle,shallowClone,show,shuffle,similarity,size,sleep,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,standardDeviation,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,timeTaken,times,toCamelCase,toCurrency,toDecimalMark,toKebabCase,toOrdinalSuffix,toSafeInteger,toSnakeCase,toggleClass,tomorrow,transform,truncateString,truthCheckCollection,unary,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,untildify,unzip,unzipWith,validateNumber,without,words,xProd,yesNo,zip,zipObject,zipWith,}
|
||||
var imports = {JSONToFile,RGBToHex,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,all,allBy,anagrams,any,anyBy,approximatelyEqual,arrayToHtmlList,ary,atob,attempt,average,averageBy,bifurcate,bifurcateBy,bind,bindAll,bindKey,binomialCoefficient,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compose,composeRight,converge,copyToClipboard,countBy,countOccurrences,createElement,createEventHub,currentURL,curry,debounce,decapitalize,deepClone,deepFlatten,defaults,defer,degreesToRads,delay,detectDeviceType,difference,differenceBy,differenceWith,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterNonUnique,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,forOwn,forOwnRight,formatDuration,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,inRange,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isArrayLike,isBoolean,isDivisible,isEmpty,isEven,isFunction,isLowerCase,isNil,isNull,isNumber,isObject,isObjectLike,isPlainObject,isPrime,isPrimitive,isPromiseLike,isSorted,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,join,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapObject,mapValues,mask,matches,matchesWith,maxBy,maxN,median,memoize,merge,minBy,minN,mostPerformant,negate,none,noneBy,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,omit,omitBy,on,onUserInputChange,once,orderBy,over,overArgs,palindrome,parseCookie,partial,partialRight,partition,percentile,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,radsToDegrees,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,redirect,reduceSuccessive,reduceWhich,reducedFilter,remove,removeNonASCII,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,setStyle,shallowClone,show,shuffle,similarity,size,sleep,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,standardDeviation,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,timeTaken,times,toCamelCase,toCurrency,toDecimalMark,toKebabCase,toOrdinalSuffix,toSafeInteger,toSnakeCase,toggleClass,tomorrow,transform,truncateString,truthCheckCollection,unary,uncurry,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,untildify,unzip,unzipWith,validateNumber,without,words,xProd,yesNo,zip,zipObject,zipWith,}
|
||||
|
||||
export default imports;
|
||||
|
||||
64
dist/_30s.js
vendored
64
dist/_30s.js
vendored
@ -31,6 +31,10 @@ const UUIDGeneratorNode = () =>
|
||||
(c ^ (crypto$1.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
|
||||
);
|
||||
|
||||
const all = arr => arr.every(Boolean);
|
||||
|
||||
const allBy = (arr, fn) => arr.every(fn);
|
||||
|
||||
const anagrams = str => {
|
||||
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
||||
return str
|
||||
@ -42,6 +46,12 @@ const anagrams = str => {
|
||||
);
|
||||
};
|
||||
|
||||
const any = arr => arr.some(Boolean);
|
||||
|
||||
const anyBy = (arr, fn) => arr.some(fn);
|
||||
|
||||
const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
|
||||
|
||||
const arrayToHtmlList = (arr, listID) =>
|
||||
arr.map(item => (document.querySelector('#' + listID).innerHTML += `<li>${item}</li>`));
|
||||
|
||||
@ -63,6 +73,12 @@ const averageBy = (arr, fn) =>
|
||||
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
|
||||
arr.length;
|
||||
|
||||
const bifurcate = (arr, filter) =>
|
||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
|
||||
|
||||
const bifurcateBy = (arr, fn) =>
|
||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
|
||||
|
||||
const bind = (fn, context, ...args) =>
|
||||
function() {
|
||||
return fn.apply(context, args.concat(...arguments));
|
||||
@ -81,6 +97,17 @@ const bindKey = (context, fn, ...args) =>
|
||||
return context[fn].apply(context, args.concat(...arguments));
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
const bottomVisible = () =>
|
||||
document.documentElement.clientHeight + window.scrollY >=
|
||||
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
|
||||
@ -198,13 +225,11 @@ const currentURL = () => window.location.href;
|
||||
const curry = (fn, arity = fn.length, ...args) =>
|
||||
arity <= args.length ? fn(...args) : curry.bind(null, fn, arity, ...args);
|
||||
|
||||
const debounce = (fn, wait = 0) => {
|
||||
let inDebounce;
|
||||
return function() {
|
||||
const context = this,
|
||||
args = arguments;
|
||||
clearTimeout(inDebounce);
|
||||
inDebounce = setTimeout(() => fn.apply(context, args), wait);
|
||||
const debounce = (fn, ms = 0) => {
|
||||
let timeoutId;
|
||||
return function(...args) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), ms);
|
||||
};
|
||||
};
|
||||
|
||||
@ -225,6 +250,8 @@ const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj
|
||||
|
||||
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
||||
|
||||
const degreesToRads = deg => deg * Math.PI / 180.0;
|
||||
|
||||
const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args);
|
||||
|
||||
const detectDeviceType = () =>
|
||||
@ -760,8 +787,21 @@ const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : v
|
||||
|
||||
const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
|
||||
|
||||
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));
|
||||
};
|
||||
|
||||
const negate = func => (...args) => !func(...args);
|
||||
|
||||
const none = arr => !arr.some(Boolean);
|
||||
|
||||
const noneBy = (arr, fn) => !arr.some(fn);
|
||||
|
||||
const nthArg = n => (...args) => args.slice(n)[0];
|
||||
|
||||
const nthElement = (arr, n = 0) => (n > 0 ? arr.slice(n, n + 1) : arr.slice(n))[0];
|
||||
@ -960,6 +1000,8 @@ const pullBy = (arr, ...args) => {
|
||||
pulled.forEach(v => arr.push(v));
|
||||
};
|
||||
|
||||
const radsToDegrees = rad => rad * 180.0 / Math.PI;
|
||||
|
||||
const randomHexColorCode = () => {
|
||||
let n = (Math.random() * 0xfffff * 1000000).toString(16);
|
||||
return '#' + n.slice(0, 6);
|
||||
@ -1280,6 +1322,12 @@ const truthCheckCollection = (collection, pre) => collection.every(obj => obj[pr
|
||||
|
||||
const unary = fn => val => fn(val);
|
||||
|
||||
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));
|
||||
};
|
||||
|
||||
const unescapeHTML = str =>
|
||||
str.replace(
|
||||
/&|<|>|'|"/g,
|
||||
@ -1381,7 +1429,7 @@ const zipWith = (...arrays) => {
|
||||
return fn ? result.map(arr => fn(...arr)) : result;
|
||||
};
|
||||
|
||||
var imports = {JSONToFile,RGBToHex,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,anagrams,arrayToHtmlList,ary,atob,attempt,average,averageBy,bind,bindAll,bindKey,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compose,composeRight,converge,copyToClipboard,countBy,countOccurrences,createElement,createEventHub,currentURL,curry,debounce,decapitalize,deepClone,deepFlatten,defaults,defer,delay,detectDeviceType,difference,differenceBy,differenceWith,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterNonUnique,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,forOwn,forOwnRight,formatDuration,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,inRange,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isArrayLike,isBoolean,isDivisible,isEmpty,isEven,isFunction,isLowerCase,isNil,isNull,isNumber,isObject,isObjectLike,isPlainObject,isPrime,isPrimitive,isPromiseLike,isSorted,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,join,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapObject,mapValues,mask,matches,matchesWith,maxBy,maxN,median,memoize,merge,minBy,minN,negate,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,omit,omitBy,on,onUserInputChange,once,orderBy,over,overArgs,palindrome,parseCookie,partial,partialRight,partition,percentile,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,redirect,reduceSuccessive,reduceWhich,reducedFilter,remove,removeNonASCII,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,setStyle,shallowClone,show,shuffle,similarity,size,sleep,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,standardDeviation,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,timeTaken,times,toCamelCase,toCurrency,toDecimalMark,toKebabCase,toOrdinalSuffix,toSafeInteger,toSnakeCase,toggleClass,tomorrow,transform,truncateString,truthCheckCollection,unary,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,untildify,unzip,unzipWith,validateNumber,without,words,xProd,yesNo,zip,zipObject,zipWith,}
|
||||
var imports = {JSONToFile,RGBToHex,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,all,allBy,anagrams,any,anyBy,approximatelyEqual,arrayToHtmlList,ary,atob,attempt,average,averageBy,bifurcate,bifurcateBy,bind,bindAll,bindKey,binomialCoefficient,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compose,composeRight,converge,copyToClipboard,countBy,countOccurrences,createElement,createEventHub,currentURL,curry,debounce,decapitalize,deepClone,deepFlatten,defaults,defer,degreesToRads,delay,detectDeviceType,difference,differenceBy,differenceWith,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterNonUnique,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,forOwn,forOwnRight,formatDuration,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,inRange,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isArrayLike,isBoolean,isDivisible,isEmpty,isEven,isFunction,isLowerCase,isNil,isNull,isNumber,isObject,isObjectLike,isPlainObject,isPrime,isPrimitive,isPromiseLike,isSorted,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,join,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapObject,mapValues,mask,matches,matchesWith,maxBy,maxN,median,memoize,merge,minBy,minN,mostPerformant,negate,none,noneBy,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,omit,omitBy,on,onUserInputChange,once,orderBy,over,overArgs,palindrome,parseCookie,partial,partialRight,partition,percentile,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,radsToDegrees,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,redirect,reduceSuccessive,reduceWhich,reducedFilter,remove,removeNonASCII,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,setStyle,shallowClone,show,shuffle,similarity,size,sleep,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,standardDeviation,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,timeTaken,times,toCamelCase,toCurrency,toDecimalMark,toKebabCase,toOrdinalSuffix,toSafeInteger,toSnakeCase,toggleClass,tomorrow,transform,truncateString,truthCheckCollection,unary,uncurry,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,untildify,unzip,unzipWith,validateNumber,without,words,xProd,yesNo,zip,zipObject,zipWith,}
|
||||
|
||||
return imports;
|
||||
|
||||
|
||||
2
dist/_30s.min.js
vendored
2
dist/_30s.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
155
locale/el_GR.js
155
locale/el_GR.js
@ -133,9 +133,9 @@ module.exports = {
|
||||
'btoa' : {
|
||||
'description': `### btoa
|
||||
|
||||
Δημιουργεί a base-64 encoded ASCII string from a String αντικείμενο in which each character in the string is treated as a byte of binary data.
|
||||
Δημιουργεί μια συμβολοσειρά ASCII με κωδικοποίηση base-64 από ένα αντικειμένο String στο οποίο κάθε χαρακτήρας αποτελεί ένα byte δυαδικών δεδομένων.
|
||||
|
||||
Create a \`Buffer\` for the given string with binary encoding and use \`Buffer.toString('base64')\` to return the encoded string.
|
||||
Δημιουρείται ένα \`Buffer\` για τη δεδομένη συμβολοσειρά με δυαδική κωδικοποίηση και χρησιμοποιείται η \`Buffer.toString('base64')\` για να επιστρέψει την κωδικοποιημένη συμβολοσειρά.
|
||||
|
||||
`,
|
||||
'comments': [`// 'Zm9vYmFy'`],
|
||||
@ -144,20 +144,20 @@ Create a \`Buffer\` for the given string with binary encoding and use \`Buffer.t
|
||||
'byteSize' : {
|
||||
'description': `### byteSize
|
||||
|
||||
Επιστρέφει the length of a string in bytes.
|
||||
Επιστρέφει το μήκος μίας συμβολοσειράς σε byte.
|
||||
|
||||
Convert a given string to a [\`Blob\` Object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and find its \`size\`.
|
||||
Μετατρέπει τη δεδομένη συμβολοσειρά σε ένα [αντικείμενο \`Blob\`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) και βρίσκει το \`size\` της.
|
||||
|
||||
`,
|
||||
'comments': [`//developer.mozilla.org/en-US/docs/Web/API/Blob) and find its \`size\`.`,`// 4`,`// 11`],
|
||||
'comments': [`//developer.mozilla.org/en-US/docs/Web/API/Blob) και βρίσκει το \`size\` της.`,`// 4`,`// 11`],
|
||||
'hash': '1848a81b6d95cc66138d877364bcbb3de7b89ebc4d2031348aa95345602f4a60'
|
||||
},
|
||||
'call' : {
|
||||
'description': `### call
|
||||
|
||||
Given a key and a set of arguments, call them when given a context. Primarily useful in composition.
|
||||
Δεδομένου ενός key και ενός συνόλου ορισμάτων, καλούνται με ένα δεδομένο context. Κυρίως χρήσιμο σε σύνθεση συναρτήσεων.
|
||||
|
||||
Χρησιμοποιείται a closure to call a stored key with stored arguments.
|
||||
Χρησιμοποιείται ένα closure για να κληθεί ένα αποθηκευμένο key με τα αποθηκευμένα ορίσματα.
|
||||
|
||||
`,
|
||||
'comments': [`//[ 2, 4, 6 ]`,`//[ 2, 4, 6 ]`],
|
||||
@ -166,10 +166,10 @@ Given a key and a set of arguments, call them when given a context. Primarily us
|
||||
'capitalize' : {
|
||||
'description': `### capitalize
|
||||
|
||||
Capitalizes the first letter of a string.
|
||||
Μετατρέπει το πρώτο γράμμα μιας συμβολοσειράς σε κεφαλαίο.
|
||||
|
||||
Χρησιμοποιείται πίνακα destructuring and \`String.toUpperCase()\` to capitalize first letter, \`...rest\` to get πίνακα of characters after first letter and then \`Array.join('')\` to make it a string again.
|
||||
Omit the \`lowerRest\` parameter to keep the rest of the string intact,ήset it to \`true\` to convert to lowercase.
|
||||
Χρησιμοποιείται αποδόμηση πίνακα και η μέθοδος \`String.toUpperCase()\` για να μετατραπεί το πρώτο γράμμα σε κεφαλαίο, η εντολή \`...rest\` για να ληφθούν τα υπόλοιπα στοιχεία του πίνακα εκτός του πρώτου γράμματος και τέλος η μέθοδος \`Array.join('')\` για να μετατραπεί και πάλι σε συμβολοσειρά.
|
||||
Αν παραληφθεί η παράμετρος \`lowerRest\`, τα υπόλοιπα γράμματα παραμένουν ως έχουν, αν όμως τεθεί \`true\` μετατρέπονται σε πεζά.
|
||||
|
||||
`,
|
||||
'comments': [`// 'FooBar'`,`// 'Foobar'`],
|
||||
@ -178,9 +178,9 @@ Omit the \`lowerRest\` parameter to keep the rest of the string intact,ήset it
|
||||
'capitalizeEveryWord' : {
|
||||
'description': `### capitalizeEveryWord
|
||||
|
||||
Capitalizes the first letter of every word in a string.
|
||||
Μετατρέπει το πρώτο γράμμα κάθε λέξης μιας συμβολοσειράς σε κεφαλαίο.
|
||||
|
||||
Χρησιμοποιείται \`String.replace()\` to match the first character of each word and \`String.toUpperCase()\` to capitalize it.
|
||||
Χρησιμοποιείται η μέθοδος \`String.replace()\` για να βρεθεί το πρώτο γράμμα κάθε λέξης και η μέθοδος \`String.toUpperCase()\` για να το μετατρέψει σε κεφαλαίο.
|
||||
|
||||
`,
|
||||
'comments': [`// 'Hello World!'`],
|
||||
@ -189,9 +189,9 @@ Capitalizes the first letter of every word in a string.
|
||||
'castArray' : {
|
||||
'description': `### castArray
|
||||
|
||||
Casts the provided value as an πίνακα if it's not one.
|
||||
Μετατρέπει τη δεδομένη τιμή σε πίνακα, αν δεν είναι ήδη πίνακας.
|
||||
|
||||
Χρησιμοποιείται \`Array.isArray()\` to determine if \`val\` is an πίνακα and return it as-isήencapsulated in an πίνακα accordingly.
|
||||
Χρησιμοποιείται η μέθοδος \`Array.isArray()\` για να ελεγχθεί αν η μεταβλητή \`val\` είναι πίνακας και ανάλογα επιστρέφεται όπως είναι ή ως πίνακας ενός στοιχείου.
|
||||
|
||||
`,
|
||||
'comments': [`// ['foo']`,`// [1]`],
|
||||
@ -200,9 +200,9 @@ Casts the provided value as an πίνακα if it's not one.
|
||||
'chainAsync' : {
|
||||
'description': `### chainAsync
|
||||
|
||||
Chains asynchronous functions.
|
||||
Συνδέει σειριακά ασύγχρονες συναρτήσεις.
|
||||
|
||||
Loop through an πίνακα of functions containing asynchronous events, calling \`next\` when each asynchronous event has completed.
|
||||
Διατρέχει ένα πίνακα συναρτήσεων που περιέχει ασύγχρονα γεγονότα, καλώντας τη \`next\` όταν ένα ασύγχρονο γεγονός έχει ολοκληρωθεί.
|
||||
|
||||
`,
|
||||
'comments': [],
|
||||
@ -211,11 +211,11 @@ Loop through an πίνακα of functions containing asynchronous events, callin
|
||||
'chunk' : {
|
||||
'description': `### chunk
|
||||
|
||||
Chunks an πίνακα into smaller arrays of a specified size.
|
||||
Μετατρέπει ένα πίνακα σε μικρότερους πίνακες με το καθορισμένο μέγεθος.
|
||||
|
||||
Χρησιμοποιείται \`Array.from()\` to create a new array, that fits the number of chunks that will be produced.
|
||||
Χρησιμοποιείται \`Array.slice()\` to map each element of the new πίνακα to a chunk the length of \`size\`.
|
||||
If the original πίνακα can't be split evenly, the final chunk will contain the remaining elements.
|
||||
Χρησιμοποιείται η μέθοδος \`Array.from()\` για να δημιουργηθεί ένας νέος πίνακας, που χωράει τον αριθμό των πινάκων που θα παραχθούν.
|
||||
Χρησιμοποιείται η μέθοδος \`Array.slice()\` για να γίνει map κάθε στοιχείο του νέου πίνακα σε μια πλειάδα στοιχείων μήκους \`size\`.
|
||||
Αν ο αρχικός πίνακας δε μπορεί να χωριστεί σε ίσα τμήματα, ο τελευταίος υποπίνακας θα περιέχει τα εναπομείναντα στοιχεία.
|
||||
|
||||
`,
|
||||
'comments': [`// [[1,2],[3,4],[5]]`],
|
||||
@ -224,10 +224,10 @@ If the original πίνακα can't be split evenly, the final chunk will contain
|
||||
'clampNumber' : {
|
||||
'description': `### clampNumber
|
||||
|
||||
Clamps \`num\` within the inclusive range specified by the boundary values \`a\` and \`b\`.
|
||||
Περιορίζει ένα αριθμό \`num\` μέσα στο εύρος τιμών που περικλείεται ανάμεσα στις τιμές \`a\` και \`b\` (περιλαμβάνοντας τα άκρα).
|
||||
|
||||
If \`num\` falls within the range, return \`num\`.
|
||||
Otherwise, return the nearest number in the range.
|
||||
Αν ο αριθμός \`num\` είναι μέσα στο εύρος τιμών, επιστρέφεται ο αριθμός \`num\`.
|
||||
Αλλιώς, επιστρέφεται ο κοντινότερος αριθμός μέσα στο εύρος τιμών.
|
||||
|
||||
`,
|
||||
'comments': [`// 3`,`// -1`],
|
||||
@ -236,9 +236,9 @@ Otherwise, return the nearest number in the range.
|
||||
'cloneRegExp' : {
|
||||
'description': `### cloneRegExp
|
||||
|
||||
Clones a regular expression.
|
||||
Κλωνοποιεί μία κανονική έκφραση (regular expression).
|
||||
|
||||
Χρησιμοποιείται \`new RegExp()\`, \`RegExp.source\` and \`RegExp.flags\` to clone the given regular expression.
|
||||
Χρησιμοποιείται μία \`new RegExp()\`, οι μέθοδοι \`RegExp.source\` και \`RegExp.flags\` για να κλωνοποιηθεί η δεδομένη κανονική έκφραση.
|
||||
|
||||
`,
|
||||
'comments': [`// /lorem ipsum/gi`],
|
||||
@ -247,9 +247,9 @@ Clones a regular expression.
|
||||
'coalesce' : {
|
||||
'description': `### coalesce
|
||||
|
||||
Επιστρέφει the first non-null/undefined argument.
|
||||
Επιστρέφει το πρώτο όρισμα που δεν είναι null ή undefined.
|
||||
|
||||
Χρησιμοποιείται \`Array.find()\` to return the first non \`null\`/\`undefined\` argument.
|
||||
Χρησιμοποιείται η μέθοδος \`Array.find()\` για να επιστρέψει το πρώτο όρισμα που δεν είναι \`null\` ή \`undefined\`.
|
||||
|
||||
`,
|
||||
'comments': [`// ""`],
|
||||
@ -258,9 +258,9 @@ Clones a regular expression.
|
||||
'coalesceFactory' : {
|
||||
'description': `### coalesceFactory
|
||||
|
||||
Επιστρέφει a customized coalesce συνάρτηση that returns the first argument that returns \`true\` from the provided argument validation function.
|
||||
Επιστρέφει μία συνάρτηση που επιστρέφει το πρώτο όρισμα που επιστρέφει \`true\` από τη δεδομένη συνάρτηση επικύρωσης ορισμάτων.
|
||||
|
||||
Χρησιμοποιείται \`Array.find()\` to return the first argument that returns \`true\` from the provided argument validation function.
|
||||
Χρησιμοποιείται η μέθοδος \`Array.find()\` για να επιστρέψει το πρώτο όρισμα που επιστρέφει \`true\` από τη δεδομένη συνάρτηση επικύρωσης ορισμάτων.
|
||||
|
||||
`,
|
||||
'comments': [`// "Waldo"`],
|
||||
@ -269,32 +269,32 @@ Clones a regular expression.
|
||||
'collectInto' : {
|
||||
'description': `### collectInto
|
||||
|
||||
Changes a συνάρτηση that accepts an πίνακα into a variadic function.
|
||||
Μετατρέπει μία a συνάρτηση που δέχεται σαν όρισμα ένα πίνακα σε μία συνάρτηση πολλαπλών ορισμάτων (variadic).
|
||||
|
||||
Given a function, return a closure that collects all inputs into an array-accepting function.
|
||||
Δεδομένης μία συνάρτησης, επιστρέφει ένα closure που συλλέγει όλα τα δεδομένα εισόδου σε μία συνάρτηση που δέχεται σαν όρισμα ένα πίνακα.
|
||||
|
||||
`,
|
||||
'comments': [`// [1, 2, 3] (after about 2 seconds)`],
|
||||
'comments': [`// [1, 2, 3] (μετά από περίπου 2 δευτερόλεπτα)`],
|
||||
'hash': '6b57cac68ad177d8fbb30e9c586f8f9c088acf755c6c956b5387441ea3850fce'
|
||||
},
|
||||
'colorize' : {
|
||||
'description': `### colorize
|
||||
|
||||
Add special characters to text to print in color in the console (combined with \`console.log()\`).
|
||||
Προσθέτει ειδικούς χαρακτήρες σε κείμενο για να εμφανιστεί με χρώματα στην κονσόλα (σε συνδυασμό με τη μέθοδο \`console.log()\`).
|
||||
|
||||
Χρησιμοποιείται template literals and special characters to add the appropriate color code to the string output.
|
||||
For background colors, add a special character that resets the background color at the end of the string.
|
||||
Χρησιμοποιούνται template literals και ειδικοί χαρακτήρες για να προστεθεί ο κατάλληλος κωδικός χρώματος στη συμβολοσειρά.
|
||||
Για χρώματα φόντου, προστίθεται ένας επιπλέον ειδικός χαρακτήρας που καθαρίζει το χρώμα παρασκηνίου μετά το τέλος της συμβολοσειράς.
|
||||
|
||||
`,
|
||||
'comments': [`// 'foo' (red letters)`,`// 'foo bar' (blue background)`,`// 'foo bar' (first word in yellow letters, second word in green letters, white background for both)`],
|
||||
'comments': [`// 'foo' (κόκκινα γράμματα)`,`// 'foo bar' (μπλε φόντο)`,`// 'foo bar' (η πρώτη λέξη με κίτρινα γράμματα, η δεύτερη με πράσινα γράμματα, λευκό φόντο και για τις δυο)`],
|
||||
'hash': '4f42f00e7d675d21829a5fcd2ab2e3fa2058d1c1b1d6850ff28f2a424364593e'
|
||||
},
|
||||
'compact' : {
|
||||
'description': `### compact
|
||||
|
||||
Removes falsey values from an array.
|
||||
Αφαιρεί όσες τιμές αξιολογούνται ως false σε ένα πίνακα.
|
||||
|
||||
Χρησιμοποιείται \`Array.filter()\` to filter out falsey values (\`false\`, \`null\`, \`0\`, \`""\`, \`undefined\`, and \`NaN\`).
|
||||
Χρησιμοποιείται η μέθοδος \`Array.filter()\` για να αφαιρέσει τις τιμές (\`false\`, \`null\`, \`0\`, \`""\`, \`undefined\`, and \`NaN\`).
|
||||
|
||||
`,
|
||||
'comments': [`// [ 1, 2, 3, 'a', 's', 34 ]`],
|
||||
@ -303,10 +303,10 @@ Removes falsey values from an array.
|
||||
'compose' : {
|
||||
'description': `### compose
|
||||
|
||||
Performs right-to-left συνάρτηση composition.
|
||||
Εκτελεί σύνθεση συναρτήσεων από τα δεξιά προς τα αριστερά.
|
||||
|
||||
Χρησιμοποιείται \`Array.reduce()\` to perform right-to-left συνάρτηση composition.
|
||||
The last (rightmost) συνάρτηση can accept oneήmore arguments; the remaining functions must be unary.
|
||||
Χρησιμοποιείται η μέθοδος \`Array.reduce()\` για να εκτελεστεί σύνθεση συναρτήσεων από τα δεξιά προς τα αριστερά.
|
||||
Η τελευταία (δεξιότερη) συνάρτηση μπορεί να δεχτεί ένα ή περισσότερα ορίσματα, οι υπόλοιπες πρέπει να είναι μοναδιαίες.
|
||||
|
||||
`,
|
||||
'comments': [`// 15`],
|
||||
@ -315,10 +315,10 @@ The last (rightmost) συνάρτηση can accept oneήmore arguments; the rema
|
||||
'composeRight' : {
|
||||
'description': `### composeRight
|
||||
|
||||
Performs left-to-right συνάρτηση composition.
|
||||
Εκτελεί σύνθεση συναρτήσεων από τα αριστερά προς τα δεξιά.
|
||||
|
||||
Χρησιμοποιείται \`Array.reduce()\` to perform left-to-right συνάρτηση composition.
|
||||
The first (leftmost) συνάρτηση can accept oneήmore arguments; the remaining functions must be unary.
|
||||
Χρησιμοποιείται η μέθοδος \`Array.reduce()\` για να εκτελεστεί σύνθεση συναρτήσεων από τα αριστερά προς τα δεξιά.
|
||||
Η πρώτη (αριστερότερη) συνάρτηση μπορεί να δεχτεί ένα ή περισσότερα ορίσματα, οι υπόλοιπες πρέπει να είναι μοναδιαίες.
|
||||
|
||||
`,
|
||||
'comments': [`// 9`],
|
||||
@ -327,10 +327,10 @@ The first (leftmost) συνάρτηση can accept oneήmore arguments; the rema
|
||||
'converge' : {
|
||||
'description': `### converge
|
||||
|
||||
Accepts a converging συνάρτηση and a list of branching functions and returns a συνάρτηση that applies each branching συνάρτηση to the ορίσματα and the results of the branching functions are passed as ορίσματα to the converging function.
|
||||
Δέχεται μια συγκλίνουσα συνάρτηση και μία λίστα συναρτήσεων διακλάδωσης και επιστρέφει μια συνάρτηση που εφαρμόζει κάθε συνάρτηση διακλάδωσης στα ορίσματα και τα αποτελέσματά τους δίνονται ως ορίσματα στη συγκλίνουσα συνάρτηση.
|
||||
|
||||
Χρησιμοποιείται \`Array.map()\` and \`Function.apply()\` to apply each συνάρτηση to the given arguments.
|
||||
Χρησιμοποιείται the spread operator (\`...\`) to call \`coverger\` with the results of all other functions.
|
||||
Χρησιμοποιούνται οι μέθοδοι \`Array.map()\` και \`Function.apply()\` για να εφαρμοστεί κάθε συνάρτηση στα δεδομένα ορίσματα.
|
||||
Χρησιμοποιείται ο τελεστής spread (\`...\`) για να κληθεί η μέθοδος \`coverger\` με τα αποτελέσματα των άλλων μεθόδων.
|
||||
|
||||
`,
|
||||
'comments': [`// 4`],
|
||||
@ -339,25 +339,25 @@ Accepts a converging συνάρτηση and a list of branching functions and re
|
||||
'copyToClipboard' : {
|
||||
'description': `### copyToClipboard
|
||||
|
||||
Copy a string to the clipboard. Only works as a result of user action (i.e. inside a \`click\` event listener).
|
||||
Αντιγράφει μια συμβολοσειρά στο πρόχειρο. Λειτουργεί μόνο σαν αποτέλεσμα ενέργειας χρήστη (δηλαδή μέσα σε ένα event listener για \`click\`).
|
||||
|
||||
Create a new \`<textarea>\` element, fill it with the supplied data and add it to the HTML document.
|
||||
Χρησιμοποιείται \`Selection.getRangeAt()\`to store the selected range (if any).
|
||||
Χρησιμοποιείται \`document.execCommand('copy')\` to copy to the clipboard.
|
||||
Remove the \`<textarea>\` element from the HTML document.
|
||||
Finally, use \`Selection().addRange()\` to recover the original selected range (if any).
|
||||
Δημιουργείται ένα νέο στοιχείο \`<textarea>\`, γεμίζεται με τα παρχεόμενα δεδομένα και προστίθεται στο έγγραφο HTML.
|
||||
Χρησιμοποιείται η μέθοδος \`Selection.getRangeAt()\` για να αποθηκεύσει το επιλεγμένο εύρος (αν υπάρχει).
|
||||
Χρησιμοποιείται η μέθοδος \`document.execCommand('copy')\` για να γίνει αντιγραφή στο πρόχειρο.
|
||||
Αφαιρείται το στοιχείο \`<textarea>\` από το έγγραφο HTML.
|
||||
Τέλος, χρησιμοποιείται η μέθοδος \`Selection().addRange()\` για να γίνει ανάκτηση του επιλεγμένου έυρους (αν υπήρχε).
|
||||
|
||||
`,
|
||||
'comments': [`// 'Lorem ipsum' copied to clipboard.`],
|
||||
'comments': [`// 'Lorem ipsum' αντεγραμμένο στο πρόχειρο.`],
|
||||
'hash': 'c496300a947ef9aabbe72f79c7ba0ca85c3a816eb54cbc8bb44ea5830b5380c9'
|
||||
},
|
||||
'countBy' : {
|
||||
'description': `### countBy
|
||||
|
||||
Groups the elements of an πίνακα based on the given συνάρτηση and returns the count of elements in each group.
|
||||
Ομαδοποιεί τα στοιχεία ενός πίνακα με βάση τη δεδομένη συνάρτηση και επιστρέφει το πλήθος των στοιχείων σε κάθε ομάδα.
|
||||
|
||||
Χρησιμοποιείται \`Array.map()\` to map the values of an πίνακα to a functionήproperty name.
|
||||
Χρησιμοποιείται \`Array.reduce()\` to create an object, where the keys are produced from the mapped results.
|
||||
Χρησιμοποιείται η μέθοδος \`Array.map()\` για να γίνει map των τιμών του πίνακα σε ένα όνομα συνάρτησης ή ιδιότητας.
|
||||
Χρησιμοποιείται η μέθοδος \`Array.reduce()\` για να δημιουργηθεί ένα αντικείμενο, το οποίου τα keys παράγονται από τα αποτελέσματα του προηγούμενου mapping.
|
||||
|
||||
`,
|
||||
'comments': [`// {4: 1, 6: 2}`,`// {3: 2, 5: 1}`],
|
||||
@ -366,9 +366,9 @@ Groups the elements of an πίνακα based on the given συνάρτηση and
|
||||
'countOccurrences' : {
|
||||
'description': `### countOccurrences
|
||||
|
||||
Counts the occurrences of a value in an array.
|
||||
Μετρά το πλήθος εμφανίσεων μια τιμής σε ένα πίνακα.
|
||||
|
||||
Χρησιμοποιείται \`Array.reduce()\` to increment a counter each time you encounter the specific value inside the array.
|
||||
Χρησιμοποιείται η μέθοδος \`Array.reduce()\` για να επαυξηθεί ένας μετρητής κάθε φορά που συναντάται ένα στοιχείο με τη συγκεκριμένη τιμή μέσα στον πίνακα.
|
||||
|
||||
`,
|
||||
'comments': [`// 3`],
|
||||
@ -377,12 +377,12 @@ Counts the occurrences of a value in an array.
|
||||
'createElement' : {
|
||||
'description': `### createElement
|
||||
|
||||
Δημιουργεί an element from a string (without appending it to the document).
|
||||
If the given string contains multiple elements, only the first one will be returned.
|
||||
Δημιουργεί ένα στοιχείο από μία συμβολοσειρά (χωρίς να το προσθέτει στο έγγραφο).
|
||||
Αν η δεδομένη συμβολοσειρά περιέχει πολλαπλά στοιχεία, μόνο το πρώτο θα επιστραφεί.
|
||||
|
||||
Χρησιμοποιείται \`document.createElement()\` to create a new element.
|
||||
Set its \`innerHTML\` to the string supplied as the argument.
|
||||
Χρησιμοποιείται \`ParentNode.firstElementChild\` to return the element version of the string.
|
||||
Χρησιμοποιείται η μέθοδος \`document.createElement()\` για να δημιουργηθεί ένα στοιχείο.
|
||||
Τίθεται το \`innerHTML\` του στη συμβολοσειρά που δόθηκε ως όρισμα.
|
||||
Χρησιμοποιείται η ιδιότητα \`ParentNode.firstElementChild\` για να επιστραφεί το στοιχείο που έχει παραχθεί.
|
||||
|
||||
`,
|
||||
'comments': [`// 'container'`],
|
||||
@ -391,24 +391,23 @@ Set its \`innerHTML\` to the string supplied as the argument.
|
||||
'createEventHub' : {
|
||||
'description': `### createEventHub
|
||||
|
||||
Δημιουργεί a pub/sub ([publish–subscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) event hub with \`emit\`, \`on\`, and \`off\` methods.
|
||||
Δημιουργεί ένα κεντρικό σημείο γεγονότων pub/sub ([publish–subscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) με μεθόδους \`emit\`, \`on\`, και \`off\`.
|
||||
|
||||
Χρησιμοποιείται \`Object.create(null)\` to create an empty \`hub\` αντικείμενο that does not inherit properties from \`Object.prototype\`.
|
||||
For \`emit\`, resolve the πίνακα of handlers based on the \`event\` argument and then run each one with \`Array.forEach()\` by passing in the data as an argument.
|
||||
For \`on\`, create an πίνακα for the event if it does not yet exist, then use \`Array.push()\` to add the handler
|
||||
to the array.
|
||||
For \`off\`, use \`Array.findIndex()\` to find the index of the handler in the event πίνακα and remove it using \`Array.splice()\`.
|
||||
Χρησιμοποιείται η μέθοδος \`Object.create(null)\` για να δημιουργήσει ένα άδειο αντικείμενο \`hub\` που δεν κληρονομεί ιδιότητες από το \`Object.prototype\`.
|
||||
Για τη μέθοδο \`emit\`, αναλύεται ο πίνακας χειριστών με βάση το όρσμα \`event\` και έπειτα εκτελείται κάθε ένας με τη μέθοδο \`Array.forEach()\`, περνώντας τα δεδομένα σαν όρισμα.
|
||||
Για τη μέθοδο \`on\`, δημιουργείται ένας πίνακας για το γεγονός αν δεν υπάρχει ήδη, έπειτα χρησιμοποιείται η μέθοδος \`Array.push()\` για να προστεθεί ο χειριστής στον πίνακα.
|
||||
Για τη μέθοδο \`off\`, χρησιμοποιείται η μέθοδος \`Array.findIndex()\` για να βρεθεί ο δείκτη του χειριστή στον πίνακα γεγονότων και αφαιρείται με χρήση της μεθόδου \`Array.splice()\`.
|
||||
|
||||
`,
|
||||
'comments': [`//en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) event hub with \`emit\`, \`on\`, and \`off\` methods.`,`// Subscribe: listen for different types of events`,`// Publish: emit events to invoke all handlers subscribed to them, passing the data to them as an argument`,`// logs 'hello world' and 'Message event fired'`,`// logs the αντικείμενο and 'Message event fired'`,`// \`increment\` variable is now 1`,`// Unsubscribe: stop a specific handler from listening to the 'message' event`],
|
||||
'comments': [`//en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) με μεθόδους \`emit\`, \`on\`, και \`off\`.`,`// Εγγραφή: ακούε για διάφορα είδη γεγονότων`,`// Δημοσίευση: εκπέμπει γεγονότα για να κληθούν όλοι οι χειριστές που έχουν εγγραφεί σε αυτά, περνώντας τα δεδομένα σαν όρισμα`,`// καταγράφει 'hello world' και 'Message event fired'`,`// καταγράφει το αντικείμενο και 'Message event fired'`,`// η μεταβλητή \`increment\` είναι πλέον 1`,`// Απεγγραφή: σταματάει ένα χειριστή να ακούει για το γεγονός 'message'`],
|
||||
'hash': 'e952a30a27c1465ea9ac465d4b7de3f9dda6e58279c176bc7c0e98fb6d99f1fc'
|
||||
},
|
||||
'currentURL' : {
|
||||
'description': `### currentURL
|
||||
|
||||
Επιστρέφει the current URL.
|
||||
Επιστρέφει την τρέχουσα διεύθυνση URL.
|
||||
|
||||
Χρησιμοποιείται \`window.location.href\` to get current URL.
|
||||
Χρησιμοποιείται η μέθοδος \`window.location.href\` για να ληφθεί η τρέχουσα διεύθυνση URL.
|
||||
|
||||
`,
|
||||
'comments': [`// 'https://google.com'`],
|
||||
@ -417,12 +416,12 @@ For \`off\`, use \`Array.findIndex()\` to find the index of the handler in the e
|
||||
'curry' : {
|
||||
'description': `### curry
|
||||
|
||||
Curries a function.
|
||||
Κάνει curry σε μία συνάρτηση.
|
||||
|
||||
Χρησιμοποιείται recursion.
|
||||
If the number of provided ορίσματα (\`args\`) is sufficient, call the passed συνάρτηση \`fn\`.
|
||||
Otherwise, return a curried συνάρτηση \`fn\` that expects the rest of the arguments.
|
||||
If you want to curry a συνάρτηση that accepts a variable number of ορίσματα (a variadic function, e.g. \`Math.min()\`), you can προαιρετικά pass the number of ορίσματα to the second parameter \`arity\`.
|
||||
Χρησιμοποιείται αναδρομή.
|
||||
Αν ο αριθμός των παρεχόμενων ορισμάτων (\`args\`) είναι επαρκής, καλείται η δεδομένη συνάρτηση \`fn\`.
|
||||
Αλλιώς, επιστρέφεται μια curried συνάρτηση \`fn\` που δέχεται τα υπόλοιπα ορίσματα.
|
||||
Αν θέλετε να κάνετε curry μια συνάρτηση που δέχεται ένα μεταβλητό αριθμό ορισμάτων (μια variadic συνάρτηση, π.χ. τη μέθοδο \`Math.min()\`), μπορείτε προεραιτικά να δηλώσετε τον αριθμό των ορισμάτων ως τη δεύτερη παράμετρο, \`arity\`.
|
||||
|
||||
`,
|
||||
'comments': [`// 1024`,`// 2`],
|
||||
|
||||
@ -10,5 +10,5 @@ const functionName = arguments =>
|
||||
```
|
||||
|
||||
```js
|
||||
functionName('sampleInput') // 'sampleOutput'
|
||||
functionName('sampleInput'); // 'sampleOutput'
|
||||
```
|
||||
|
||||
13
snippets/all.md
Normal file
13
snippets/all.md
Normal file
@ -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
|
||||
```
|
||||
13
snippets/allBy.md
Normal file
13
snippets/allBy.md
Normal file
@ -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
|
||||
```
|
||||
13
snippets/any.md
Normal file
13
snippets/any.md
Normal file
@ -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
|
||||
```
|
||||
13
snippets/anyBy.md
Normal file
13
snippets/anyBy.md
Normal file
@ -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
|
||||
```
|
||||
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
|
||||
```
|
||||
31
snippets/mostPerformant.md
Normal file
31
snippets/mostPerformant.md
Normal file
@ -0,0 +1,31 @@
|
||||
### mostPerformant
|
||||
|
||||
Returns the index of the function in an array of functions which executed the fastest.
|
||||
|
||||
Use `Array.map()` to generate an array where each value is the total time taken to execute the function after `iterations` times. Use the difference in `performance.now()` values before and after to get the total time in milliseconds to a high degree of accuracy.
|
||||
Use `Math.min()` to find the minimum execution time, and return the index of that shortest time which corresponds to the index of the most performant function.
|
||||
Omit the second argument, `iterations`, to use a default of 10,000 iterations. The more iterations, the more reliable the result but the longer it will take.
|
||||
|
||||
```js
|
||||
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));
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
mostPerformant([
|
||||
() => {
|
||||
// Loops through the entire array before returning `false`
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, '10'].every(el => typeof el === 'number');
|
||||
},
|
||||
() => {
|
||||
// Only needs to reach index `1` before returning false
|
||||
[1, '2', 3, 4, 5, 6, 7, 8, 9, 10].every(el => typeof el === 'number');
|
||||
}
|
||||
]); // 1
|
||||
```
|
||||
13
snippets/none.md
Normal file
13
snippets/none.md
Normal file
@ -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
|
||||
```
|
||||
13
snippets/noneBy.md
Normal file
13
snippets/noneBy.md
Normal file
@ -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
|
||||
```
|
||||
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
|
||||
```
|
||||
14
tag_database
14
tag_database
@ -1,13 +1,21 @@
|
||||
all:array
|
||||
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
|
||||
@ -40,6 +48,7 @@ deepClone:object,recursion
|
||||
deepFlatten:array,recursion
|
||||
defaults:object
|
||||
defer:function
|
||||
degreesToRads:math
|
||||
delay:function
|
||||
detectDeviceType:browser
|
||||
difference:array,math
|
||||
@ -153,7 +162,10 @@ memoize:function
|
||||
merge:object,array
|
||||
minBy:math,array,function
|
||||
minN:array,math
|
||||
mostPerformant:utility,function
|
||||
negate:function
|
||||
none:array
|
||||
noneBy:array,function
|
||||
nthArg:utility,function
|
||||
nthElement:array
|
||||
objectFromPairs:object,array
|
||||
@ -187,6 +199,7 @@ pull:array
|
||||
pullAtIndex:array
|
||||
pullAtValue:array
|
||||
pullBy:array,function,advanced
|
||||
radsToDegrees:math
|
||||
randomHexColorCode:utility,random
|
||||
randomIntArrayInRange:math,utility,random
|
||||
randomIntegerInRange:math,utility,random
|
||||
@ -252,6 +265,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/all/all.js
Normal file
2
test/all/all.js
Normal file
@ -0,0 +1,2 @@
|
||||
const all = arr => arr.every(Boolean);
|
||||
module.exports = all;
|
||||
19
test/all/all.test.js
Normal file
19
test/all/all.test.js
Normal file
@ -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();
|
||||
});
|
||||
2
test/allBy/allBy.js
Normal file
2
test/allBy/allBy.js
Normal file
@ -0,0 +1,2 @@
|
||||
const allBy = (arr, fn) => arr.every(fn);
|
||||
module.exports = allBy;
|
||||
15
test/allBy/allBy.test.js
Normal file
15
test/allBy/allBy.test.js
Normal file
@ -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();
|
||||
});
|
||||
2
test/any/any.js
Normal file
2
test/any/any.js
Normal file
@ -0,0 +1,2 @@
|
||||
const any = arr => arr.some(Boolean);
|
||||
module.exports = any;
|
||||
16
test/any/any.test.js
Normal file
16
test/any/any.test.js
Normal file
@ -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();
|
||||
});
|
||||
2
test/anyBy/anyBy.js
Normal file
2
test/anyBy/anyBy.js
Normal file
@ -0,0 +1,2 @@
|
||||
const anyBy = (arr, fn) => arr.some(fn);
|
||||
module.exports = anyBy;
|
||||
15
test/anyBy/anyBy.test.js
Normal file
15
test/anyBy/anyBy.test.js
Normal file
@ -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();
|
||||
});
|
||||
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();
|
||||
});
|
||||
@ -1,10 +1,8 @@
|
||||
const debounce = (fn, wait = 0) => {
|
||||
let inDebounce;
|
||||
return function() {
|
||||
const context = this,
|
||||
args = arguments;
|
||||
clearTimeout(inDebounce);
|
||||
inDebounce = setTimeout(() => fn.apply(context, args), wait);
|
||||
const debounce = (fn, ms = 0) => {
|
||||
let timeoutId;
|
||||
return function(...args) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), ms);
|
||||
};
|
||||
};
|
||||
module.exports = debounce;
|
||||
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();
|
||||
});
|
||||
9
test/mostPerformant/mostPerformant.js
Normal file
9
test/mostPerformant/mostPerformant.js
Normal file
@ -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;
|
||||
13
test/mostPerformant/mostPerformant.test.js
Normal file
13
test/mostPerformant/mostPerformant.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
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.deepEqual(mostPerformant(args..), 'Expected');
|
||||
//t.equal(mostPerformant(args..), 'Expected');
|
||||
//t.false(mostPerformant(args..), 'Expected');
|
||||
//t.throws(mostPerformant(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
2
test/none/none.js
Normal file
2
test/none/none.js
Normal file
@ -0,0 +1,2 @@
|
||||
const none = arr => !arr.some(Boolean);
|
||||
module.exports = none;
|
||||
15
test/none/none.test.js
Normal file
15
test/none/none.test.js
Normal file
@ -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();
|
||||
});
|
||||
2
test/noneBy/noneBy.js
Normal file
2
test/noneBy/noneBy.js
Normal file
@ -0,0 +1,2 @@
|
||||
const noneBy = (arr, fn) => !arr.some(fn);
|
||||
module.exports = noneBy;
|
||||
15
test/noneBy/noneBy.test.js
Normal file
15
test/noneBy/noneBy.test.js
Normal file
@ -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();
|
||||
});
|
||||
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();
|
||||
});
|
||||
99
test/testlog
99
test/testlog
@ -1,4 +1,4 @@
|
||||
Test log for: Sun Feb 11 2018 20:20:34 GMT+0000 (UTC)
|
||||
Test log for: Thu Feb 15 2018 20:32:12 GMT+0000 (UTC)
|
||||
|
||||
> 30-seconds-of-code@0.0.1 test /home/travis/build/Chalarangelo/30-seconds-of-code
|
||||
> tape test/**/*.test.js | tap-spec
|
||||
@ -35,6 +35,22 @@ Test log for: Sun Feb 11 2018 20:20:34 GMT+0000 (UTC)
|
||||
✔ Contains dashes in the proper places
|
||||
✔ Only contains hexadecimal digits
|
||||
|
||||
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
|
||||
@ -42,6 +58,27 @@ Test log for: Sun Feb 11 2018 20:20:34 GMT+0000 (UTC)
|
||||
✔ 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 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
|
||||
@ -84,6 +121,16 @@ Test log for: Sun Feb 11 2018 20:20:34 GMT+0000 (UTC)
|
||||
✔ 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
|
||||
@ -107,6 +154,15 @@ Test log for: Sun Feb 11 2018 20:20:34 GMT+0000 (UTC)
|
||||
✔ 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
|
||||
@ -299,6 +355,11 @@ Test log for: Sun Feb 11 2018 20:20:34 GMT+0000 (UTC)
|
||||
|
||||
✔ defer is a Function
|
||||
|
||||
Testing degreesToRads
|
||||
|
||||
✔ degreesToRads is a Function
|
||||
✔ Returns the appropriate value
|
||||
|
||||
Testing delay
|
||||
|
||||
✔ delay is a Function
|
||||
@ -1041,11 +1102,27 @@ Test log for: Sun Feb 11 2018 20:20:34 GMT+0000 (UTC)
|
||||
✔ 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
|
||||
✔ 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
|
||||
@ -1233,6 +1310,11 @@ Test log for: Sun Feb 11 2018 20:20:34 GMT+0000 (UTC)
|
||||
✔ 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
|
||||
@ -1631,6 +1713,13 @@ Test log for: Sun Feb 11 2018 20:20:34 GMT+0000 (UTC)
|
||||
✔ 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
|
||||
@ -1796,15 +1885,15 @@ Test log for: Sun Feb 11 2018 20:20:34 GMT+0000 (UTC)
|
||||
Testing zipWith
|
||||
|
||||
✔ zipWith is a Function
|
||||
✔ Sends a GET request
|
||||
✔ Runs the function provided
|
||||
✔ Sends a GET request
|
||||
✔ Sends a POST request
|
||||
✔ Runs promises in series
|
||||
✔ Works with multiple promises
|
||||
|
||||
|
||||
total: 901
|
||||
passing: 901
|
||||
duration: 2.4s
|
||||
total: 948
|
||||
passing: 948
|
||||
duration: 2.7s
|
||||
|
||||
|
||||
|
||||
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