Travis build: 1403
This commit is contained in:
36
README.md
36
README.md
@ -675,7 +675,7 @@ const sum = pipeAsyncFunctions(
|
|||||||
x => x + 3,
|
x => x + 3,
|
||||||
async x => (await x) + 4
|
async x => (await x) + 4
|
||||||
);
|
);
|
||||||
(async () => {
|
(async() => {
|
||||||
console.log(await sum(5)); // 15 (after one second)
|
console.log(await sum(5)); // 15 (after one second)
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
@ -1722,8 +1722,8 @@ const join = (arr, separator = ',', end = separator) =>
|
|||||||
i === arr.length - 2
|
i === arr.length - 2
|
||||||
? acc + val + end
|
? acc + val + end
|
||||||
: i === arr.length - 1
|
: i === arr.length - 1
|
||||||
? acc + val
|
? acc + val
|
||||||
: acc + val + separator,
|
: acc + val + separator,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
@ -4269,10 +4269,10 @@ const getMeridiemSuffixOfInteger = num =>
|
|||||||
num === 0 || num === 24
|
num === 0 || num === 24
|
||||||
? 12 + 'am'
|
? 12 + 'am'
|
||||||
: num === 12
|
: num === 12
|
||||||
? 12 + 'pm'
|
? 12 + 'pm'
|
||||||
: num < 12
|
: num < 12
|
||||||
? (num % 12) + 'am'
|
? (num % 12) + 'am'
|
||||||
: (num % 12) + 'pm';
|
: (num % 12) + 'pm';
|
||||||
```
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
@ -5484,11 +5484,11 @@ Throws an exception if `n` is a negative number.
|
|||||||
const factorial = n =>
|
const factorial = n =>
|
||||||
n < 0
|
n < 0
|
||||||
? (() => {
|
? (() => {
|
||||||
throw new TypeError('Negative numbers are not allowed!');
|
throw new TypeError('Negative numbers are not allowed!');
|
||||||
})()
|
})()
|
||||||
: n <= 1
|
: n <= 1
|
||||||
? 1
|
? 1
|
||||||
: n * factorial(n - 1);
|
: n * factorial(n - 1);
|
||||||
```
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
@ -6676,8 +6676,8 @@ const deepClone = obj => {
|
|||||||
return Array.isArray(obj) && obj.length
|
return Array.isArray(obj) && obj.length
|
||||||
? (clone.length = obj.length) && Array.from(clone)
|
? (clone.length = obj.length) && Array.from(clone)
|
||||||
: Array.isArray(obj)
|
: Array.isArray(obj)
|
||||||
? Array.from(obj)
|
? Array.from(obj)
|
||||||
: clone;
|
: clone;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -6765,13 +6765,13 @@ const deepMapKeys = (obj, f) =>
|
|||||||
Array.isArray(obj)
|
Array.isArray(obj)
|
||||||
? obj.map(val => deepMapKeys(val, f))
|
? obj.map(val => deepMapKeys(val, f))
|
||||||
: typeof obj === 'object'
|
: typeof obj === 'object'
|
||||||
? Object.keys(obj).reduce((acc, current) => {
|
? Object.keys(obj).reduce((acc, current) => {
|
||||||
const val = obj[current];
|
const val = obj[current];
|
||||||
acc[f(current)] =
|
acc[f(current)] =
|
||||||
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
|
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
|
||||||
return acc;
|
return acc;
|
||||||
}, {})
|
}, {})
|
||||||
: obj;
|
: obj;
|
||||||
```
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
@ -6842,9 +6842,9 @@ const dig = (obj, target) =>
|
|||||||
target in obj
|
target in obj
|
||||||
? obj[target]
|
? obj[target]
|
||||||
: Object.values(obj).reduce((acc, val) => {
|
: Object.values(obj).reduce((acc, val) => {
|
||||||
if (acc !== undefined) return acc;
|
if (acc !== undefined) return acc;
|
||||||
if (typeof val === 'object') return dig(val, target);
|
if (typeof val === 'object') return dig(val, target);
|
||||||
}, undefined);
|
}, undefined);
|
||||||
```
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|||||||
@ -19,6 +19,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const lengthIs4 = checkProp(l => l === 4, 'length');
|
const lengthIs4 = checkProp(l => l === 4, 'length');
|
||||||
lengthIs4([]); // false
|
lengthIs4([]); // false
|
||||||
lengthIs4([1,2,3,4]); // true
|
lengthIs4([1,2,3,4]); // true
|
||||||
|
|||||||
@ -10,7 +10,6 @@ Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of th
|
|||||||
Use `Object.keys()` and `Array.prototype.forEach()` to determine which key-value pairs need to be deep cloned.
|
Use `Object.keys()` and `Array.prototype.forEach()` to determine which key-value pairs need to be deep cloned.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
const deepClone = obj => {
|
const deepClone = obj => {
|
||||||
let clone = Object.assign({}, obj);
|
let clone = Object.assign({}, obj);
|
||||||
Object.keys(clone).forEach(
|
Object.keys(clone).forEach(
|
||||||
@ -19,8 +18,8 @@ const deepClone = obj => {
|
|||||||
return Array.isArray(obj) && obj.length
|
return Array.isArray(obj) && obj.length
|
||||||
? (clone.length = obj.length) && Array.from(clone)
|
? (clone.length = obj.length) && Array.from(clone)
|
||||||
: Array.isArray(obj)
|
: Array.isArray(obj)
|
||||||
? Array.from(obj)
|
? Array.from(obj)
|
||||||
: clone;
|
: clone;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -10,18 +10,17 @@ Use `Object.keys(obj)` to iterate over the object's keys.
|
|||||||
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
|
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
const deepMapKeys = (obj, f) =>
|
const deepMapKeys = (obj, f) =>
|
||||||
Array.isArray(obj)
|
Array.isArray(obj)
|
||||||
? obj.map(val => deepMapKeys(val, f))
|
? obj.map(val => deepMapKeys(val, f))
|
||||||
: typeof obj === 'object'
|
: typeof obj === 'object'
|
||||||
? Object.keys(obj).reduce((acc, current) => {
|
? Object.keys(obj).reduce((acc, current) => {
|
||||||
const val = obj[current];
|
const val = obj[current];
|
||||||
acc[f(current)] =
|
acc[f(current)] =
|
||||||
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
|
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
|
||||||
return acc;
|
return acc;
|
||||||
}, {})
|
}, {})
|
||||||
: obj;
|
: obj;
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -9,14 +9,13 @@ Use the `in` operator to check if `target` exists in `obj`.
|
|||||||
If found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found.
|
If found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
const dig = (obj, target) =>
|
const dig = (obj, target) =>
|
||||||
target in obj
|
target in obj
|
||||||
? obj[target]
|
? obj[target]
|
||||||
: Object.values(obj).reduce((acc, val) => {
|
: Object.values(obj).reduce((acc, val) => {
|
||||||
if (acc !== undefined) return acc;
|
if (acc !== undefined) return acc;
|
||||||
if (typeof val === 'object') return dig(val, target);
|
if (typeof val === 'object') return dig(val, target);
|
||||||
}, undefined);
|
}, undefined);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -11,15 +11,14 @@ Otherwise, return the product of `n` and the factorial of `n - 1`.
|
|||||||
Throws an exception if `n` is a negative number.
|
Throws an exception if `n` is a negative number.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
const factorial = n =>
|
const factorial = n =>
|
||||||
n < 0
|
n < 0
|
||||||
? (() => {
|
? (() => {
|
||||||
throw new TypeError('Negative numbers are not allowed!');
|
throw new TypeError('Negative numbers are not allowed!');
|
||||||
})()
|
})()
|
||||||
: n <= 1
|
: n <= 1
|
||||||
? 1
|
? 1
|
||||||
: n * factorial(n - 1);
|
: n * factorial(n - 1);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -8,15 +8,14 @@ Converts an integer to a suffixed string, adding `am` or `pm` based on its value
|
|||||||
Use the modulo operator (`%`) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.
|
Use the modulo operator (`%`) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
const getMeridiemSuffixOfInteger = num =>
|
const getMeridiemSuffixOfInteger = num =>
|
||||||
num === 0 || num === 24
|
num === 0 || num === 24
|
||||||
? 12 + 'am'
|
? 12 + 'am'
|
||||||
: num === 12
|
: num === 12
|
||||||
? 12 + 'pm'
|
? 12 + 'pm'
|
||||||
: num < 12
|
: num < 12
|
||||||
? (num % 12) + 'am'
|
? (num % 12) + 'am'
|
||||||
: (num % 12) + 'pm';
|
: (num % 12) + 'pm';
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -11,15 +11,14 @@ Omit the second argument, `separator`, to use a default separator of `','`.
|
|||||||
Omit the third argument, `end`, to use the same value as `separator` by default.
|
Omit the third argument, `end`, to use the same value as `separator` by default.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
const join = (arr, separator = ',', end = separator) =>
|
const join = (arr, separator = ',', end = separator) =>
|
||||||
arr.reduce(
|
arr.reduce(
|
||||||
(acc, val, i) =>
|
(acc, val, i) =>
|
||||||
i === arr.length - 2
|
i === arr.length - 2
|
||||||
? acc + val + end
|
? acc + val + end
|
||||||
: i === arr.length - 1
|
: i === arr.length - 1
|
||||||
? acc + val
|
? acc + val
|
||||||
: acc + val + separator,
|
: acc + val + separator,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|||||||
@ -14,13 +14,14 @@ const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Pr
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
const sum = pipeAsyncFunctions(
|
const sum = pipeAsyncFunctions(
|
||||||
x => x + 1,
|
x => x + 1,
|
||||||
x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),
|
x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),
|
||||||
x => x + 3,
|
x => x + 3,
|
||||||
async x => (await x) + 4
|
async x => (await x) + 4
|
||||||
);
|
);
|
||||||
(async () => {
|
(async() => {
|
||||||
console.log(await sum(5)); // 15 (after one second)
|
console.log(await sum(5)); // 15 (after one second)
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
34
test/_30s.js
34
test/_30s.js
@ -198,8 +198,8 @@ const deepClone = obj => {
|
|||||||
return Array.isArray(obj) && obj.length
|
return Array.isArray(obj) && obj.length
|
||||||
? (clone.length = obj.length) && Array.from(clone)
|
? (clone.length = obj.length) && Array.from(clone)
|
||||||
: Array.isArray(obj)
|
: Array.isArray(obj)
|
||||||
? Array.from(obj)
|
? Array.from(obj)
|
||||||
: clone;
|
: clone;
|
||||||
};
|
};
|
||||||
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
|
||||||
const deepFreeze = obj =>
|
const deepFreeze = obj =>
|
||||||
@ -211,13 +211,13 @@ const deepMapKeys = (obj, f) =>
|
|||||||
Array.isArray(obj)
|
Array.isArray(obj)
|
||||||
? obj.map(val => deepMapKeys(val, f))
|
? obj.map(val => deepMapKeys(val, f))
|
||||||
: typeof obj === 'object'
|
: typeof obj === 'object'
|
||||||
? Object.keys(obj).reduce((acc, current) => {
|
? Object.keys(obj).reduce((acc, current) => {
|
||||||
const val = obj[current];
|
const val = obj[current];
|
||||||
acc[f(current)] =
|
acc[f(current)] =
|
||||||
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
|
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
|
||||||
return acc;
|
return acc;
|
||||||
}, {})
|
}, {})
|
||||||
: obj;
|
: obj;
|
||||||
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
|
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
|
||||||
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
||||||
const degreesToRads = deg => (deg * Math.PI) / 180.0;
|
const degreesToRads = deg => (deg * Math.PI) / 180.0;
|
||||||
@ -239,9 +239,9 @@ const dig = (obj, target) =>
|
|||||||
target in obj
|
target in obj
|
||||||
? obj[target]
|
? obj[target]
|
||||||
: Object.values(obj).reduce((acc, val) => {
|
: Object.values(obj).reduce((acc, val) => {
|
||||||
if (acc !== undefined) return acc;
|
if (acc !== undefined) return acc;
|
||||||
if (typeof val === 'object') return dig(val, target);
|
if (typeof val === 'object') return dig(val, target);
|
||||||
}, undefined);
|
}, undefined);
|
||||||
const digitize = n => [...`${n}`].map(i => parseInt(i));
|
const digitize = n => [...`${n}`].map(i => parseInt(i));
|
||||||
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
||||||
const drop = (arr, n = 1) => arr.slice(n);
|
const drop = (arr, n = 1) => arr.slice(n);
|
||||||
@ -314,11 +314,11 @@ const extendHex = shortHex =>
|
|||||||
const factorial = n =>
|
const factorial = n =>
|
||||||
n < 0
|
n < 0
|
||||||
? (() => {
|
? (() => {
|
||||||
throw new TypeError('Negative numbers are not allowed!');
|
throw new TypeError('Negative numbers are not allowed!');
|
||||||
})()
|
})()
|
||||||
: n <= 1
|
: n <= 1
|
||||||
? 1
|
? 1
|
||||||
: n * factorial(n - 1);
|
: n * factorial(n - 1);
|
||||||
const fibonacci = n =>
|
const fibonacci = n =>
|
||||||
Array.from({ length: n }).reduce(
|
Array.from({ length: n }).reduce(
|
||||||
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
|
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
|
||||||
@ -419,10 +419,10 @@ const getMeridiemSuffixOfInteger = num =>
|
|||||||
num === 0 || num === 24
|
num === 0 || num === 24
|
||||||
? 12 + 'am'
|
? 12 + 'am'
|
||||||
: num === 12
|
: num === 12
|
||||||
? 12 + 'pm'
|
? 12 + 'pm'
|
||||||
: num < 12
|
: num < 12
|
||||||
? (num % 12) + 'am'
|
? (num % 12) + 'am'
|
||||||
: (num % 12) + 'pm';
|
: (num % 12) + 'pm';
|
||||||
const getScrollPosition = (el = window) => ({
|
const getScrollPosition = (el = window) => ({
|
||||||
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
|
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
|
||||||
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
|
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
|
||||||
@ -643,8 +643,8 @@ const join = (arr, separator = ',', end = separator) =>
|
|||||||
i === arr.length - 2
|
i === arr.length - 2
|
||||||
? acc + val + end
|
? acc + val + end
|
||||||
: i === arr.length - 1
|
: i === arr.length - 1
|
||||||
? acc + val
|
? acc + val
|
||||||
: acc + val + separator,
|
: acc + val + separator,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
const JSONtoCSV = (arr, columns, delimiter = ',') =>
|
const JSONtoCSV = (arr, columns, delimiter = ',') =>
|
||||||
|
|||||||
Reference in New Issue
Block a user