Travis build: 1539

This commit is contained in:
30secondsofcode
2019-11-04 07:17:49 +00:00
parent e76a83f138
commit e5522dcf4c
15 changed files with 217 additions and 143 deletions

View File

@ -121,6 +121,7 @@ _30s.average(1, 2, 3);
* [`forEachRight`](#foreachright)
* [`groupBy`](#groupby)
* [`head`](#head)
* [`includesAny`](#includesany)
* [`indexOfAll`](#indexofall)
* [`initial`](#initial)
* [`initialize2DArray`](#initialize2darray)
@ -678,7 +679,7 @@ const sum = pipeAsyncFunctions(
x => x + 3,
async x => (await x) + 4
);
(async () => {
(async() => {
console.log(await sum(5)); // 15 (after one second)
})();
```
@ -1450,6 +1451,27 @@ head([1, 2, 3]); // 1
<br>[⬆ Back to top](#contents)
### includesAny
Returns `true` if at least one element of values is included in arr , `false` otherwise.
Use `Array.prototype.some()` and `Array.prototype.includes()` to check if at least one element of `values` is included in `arr`.
```js
const includesAny = (arr, values) => values.some(v => arr.includes(v));
```
<details>
<summary>Examples</summary>
```js
includesAny([1, 2, 3, 4], [2, 9]); // true
includesAny([1, 2, 3, 4], [8, 9]); // false
```
</details>
<br>[⬆ Back to top](#contents)
### indexOfAll
Returns all indices of `val` in an array.
@ -1725,8 +1747,8 @@ const join = (arr, separator = ',', end = separator) =>
i === arr.length - 2
? acc + val + end
: i === arr.length - 1
? acc + val
: acc + val + separator,
? acc + val
: acc + val + separator,
''
);
```
@ -4274,10 +4296,10 @@ const getMeridiemSuffixOfInteger = num =>
num === 0 || num === 24
? 12 + 'am'
: num === 12
? 12 + 'pm'
: num < 12
? (num % 12) + 'am'
: (num % 12) + 'pm';
? 12 + 'pm'
: num < 12
? (num % 12) + 'am'
: (num % 12) + 'pm';
```
<details>
@ -5489,11 +5511,11 @@ Throws an exception if `n` is a negative number.
const factorial = n =>
n < 0
? (() => {
throw new TypeError('Negative numbers are not allowed!');
})()
throw new TypeError('Negative numbers are not allowed!');
})()
: n <= 1
? 1
: n * factorial(n - 1);
? 1
: n * factorial(n - 1);
```
<details>
@ -6704,8 +6726,8 @@ const deepClone = obj => {
return Array.isArray(obj) && obj.length
? (clone.length = obj.length) && Array.from(clone)
: Array.isArray(obj)
? Array.from(obj)
: clone;
? Array.from(obj)
: clone;
};
```
@ -6793,13 +6815,13 @@ const deepMapKeys = (obj, f) =>
Array.isArray(obj)
? obj.map(val => deepMapKeys(val, f))
: typeof obj === 'object'
? Object.keys(obj).reduce((acc, current) => {
? Object.keys(obj).reduce((acc, current) => {
const val = obj[current];
acc[f(current)] =
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
return acc;
}, {})
: obj;
: obj;
```
<details>
@ -6870,9 +6892,9 @@ const dig = (obj, target) =>
target in obj
? obj[target]
: Object.values(obj).reduce((acc, val) => {
if (acc !== undefined) return acc;
if (typeof val === 'object') return dig(val, target);
}, undefined);
if (acc !== undefined) return acc;
if (typeof val === 'object') return dig(val, target);
}, undefined);
```
<details>
@ -7128,11 +7150,14 @@ Return `false` beforehand if given key list is empty.
```js
const hasKey = (obj, keys) => {
return (keys.length > 0) && keys.every(key => {
if (typeof obj !== 'object' || !obj.hasOwnProperty(key)) return false;
obj = obj[key];
return true;
});
return (
keys.length > 0 &&
keys.every(key => {
if (typeof obj !== 'object' || !obj.hasOwnProperty(key)) return false;
obj = obj[key];
return true;
})
);
};
```
@ -9383,10 +9408,10 @@ Return the `queryString` or an empty string when the `queryParameters` are falsy
const objectToQueryString = queryParameters => {
return queryParameters
? Object.entries(queryParameters).reduce((queryString, [key, val], index) => {
const symbol = index === 0 ? '?' : '&';
queryString += typeof val === 'string' ? `${symbol}${key}=${val}` : '';
return queryString;
}, '')
const symbol = index === 0 ? '?' : '&';
queryString += typeof val === 'string' ? `${symbol}${key}=${val}` : '';
return queryString;
}, '')
: '';
};
```