Skip to content

Commit aacb664

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 95101e2 + f42d0dc commit aacb664

10 files changed

Lines changed: 61 additions & 53 deletions

File tree

‎README.md‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ const sum = pipeAsyncFunctions(
675675
x => x + 3,
676676
async x => (await x) + 4
677677
);
678-
(async () => {
678+
(async() => {
679679
console.log(await sum(5)); // 15 (after one second)
680680
})();
681681
```
@@ -1722,8 +1722,8 @@ const join = (arr, separator = ',', end = separator) =>
17221722
i === arr.length - 2
17231723
? acc + val + end
17241724
: i === arr.length - 1
1725-
? acc + val
1726-
: acc + val + separator,
1725+
? acc + val
1726+
: acc + val + separator,
17271727
''
17281728
);
17291729
```
@@ -4269,10 +4269,10 @@ const getMeridiemSuffixOfInteger = num =>
42694269
num === 0 || num === 24
42704270
? 12 + 'am'
42714271
: num === 12
4272-
? 12 + 'pm'
4273-
: num < 12
4274-
? (num % 12) + 'am'
4275-
: (num % 12) + 'pm';
4272+
? 12 + 'pm'
4273+
: num < 12
4274+
? (num % 12) + 'am'
4275+
: (num % 12) + 'pm';
42764276
```
42774277

42784278
<details>
@@ -5484,11 +5484,11 @@ Throws an exception if `n` is a negative number.
54845484
const factorial = n =>
54855485
n < 0
54865486
? (() => {
5487-
throw new TypeError('Negative numbers are not allowed!');
5488-
})()
5487+
throw new TypeError('Negative numbers are not allowed!');
5488+
})()
54895489
: n <= 1
5490-
? 1
5491-
: n * factorial(n - 1);
5490+
? 1
5491+
: n * factorial(n - 1);
54925492
```
54935493

54945494
<details>
@@ -6676,8 +6676,8 @@ const deepClone = obj => {
66766676
return Array.isArray(obj) && obj.length
66776677
? (clone.length = obj.length) && Array.from(clone)
66786678
: Array.isArray(obj)
6679-
? Array.from(obj)
6680-
: clone;
6679+
? Array.from(obj)
6680+
: clone;
66816681
};
66826682
```
66836683

@@ -6765,13 +6765,13 @@ const deepMapKeys = (obj, f) =>
67656765
Array.isArray(obj)
67666766
? obj.map(val => deepMapKeys(val, f))
67676767
: typeof obj === 'object'
6768-
? Object.keys(obj).reduce((acc, current) => {
6768+
? Object.keys(obj).reduce((acc, current) => {
67696769
const val = obj[current];
67706770
acc[f(current)] =
67716771
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
67726772
return acc;
67736773
}, {})
6774-
: obj;
6774+
: obj;
67756775
```
67766776

67776777
<details>
@@ -6842,9 +6842,9 @@ const dig = (obj, target) =>
68426842
target in obj
68436843
? obj[target]
68446844
: Object.values(obj).reduce((acc, val) => {
6845-
if (acc !== undefined) return acc;
6846-
if (typeof val === 'object') return dig(val, target);
6847-
}, undefined);
6845+
if (acc !== undefined) return acc;
6846+
if (typeof val === 'object') return dig(val, target);
6847+
}, undefined);
68486848
```
68496849

68506850
<details>

‎snippets/checkProp.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
2222

2323

2424

25+
2526
const lengthIs4 = checkProp(l => l === 4, 'length');
2627
lengthIs4([]); // false
2728
lengthIs4([1,2,3,4]); // true

‎snippets/deepClone.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of th
1010
Use `Object.keys()` and `Array.prototype.forEach()` to determine which key-value pairs need to be deep cloned.
1111

1212
```js
13+
1314
const deepClone = obj => {
1415
let clone = Object.assign({}, obj);
1516
Object.keys(clone).forEach(
@@ -18,8 +19,8 @@ const deepClone = obj => {
1819
return Array.isArray(obj) && obj.length
1920
? (clone.length = obj.length) && Array.from(clone)
2021
: Array.isArray(obj)
21-
? Array.from(obj)
22-
: clone;
22+
? Array.from(obj)
23+
: clone;
2324
};
2425
```
2526

‎snippets/deepMapKeys.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ Use `Object.keys(obj)` to iterate over the object's keys.
1010
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
1111

1212
```js
13+
1314
const deepMapKeys = (obj, f) =>
1415
Array.isArray(obj)
1516
? obj.map(val => deepMapKeys(val, f))
1617
: typeof obj === 'object'
17-
? Object.keys(obj).reduce((acc, current) => {
18+
? Object.keys(obj).reduce((acc, current) => {
1819
const val = obj[current];
1920
acc[f(current)] =
2021
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
2122
return acc;
2223
}, {})
23-
: obj;
24+
: obj;
2425
```
2526

2627
```js

‎snippets/dig.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ Use the `in` operator to check if `target` exists in `obj`.
99
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.
1010

1111
```js
12+
1213
const dig = (obj, target) =>
1314
target in obj
1415
? obj[target]
1516
: Object.values(obj).reduce((acc, val) => {
16-
if (acc !== undefined) return acc;
17-
if (typeof val === 'object') return dig(val, target);
18-
}, undefined);
17+
if (acc !== undefined) return acc;
18+
if (typeof val === 'object') return dig(val, target);
19+
}, undefined);
1920
```
2021

2122
```js

‎snippets/factorial.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ Otherwise, return the product of `n` and the factorial of `n - 1`.
1111
Throws an exception if `n` is a negative number.
1212

1313
```js
14+
1415
const factorial = n =>
1516
n < 0
1617
? (() => {
17-
throw new TypeError('Negative numbers are not allowed!');
18-
})()
18+
throw new TypeError('Negative numbers are not allowed!');
19+
})()
1920
: n <= 1
20-
? 1
21-
: n * factorial(n - 1);
21+
? 1
22+
: n * factorial(n - 1);
2223
```
2324

2425
```js

‎snippets/getMeridiemSuffixOfInteger.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ Converts an integer to a suffixed string, adding `am` or `pm` based on its value
88
Use the modulo operator (`%`) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.
99

1010
```js
11+
1112
const getMeridiemSuffixOfInteger = num =>
1213
num === 0 || num === 24
1314
? 12 + 'am'
1415
: num === 12
15-
? 12 + 'pm'
16-
: num < 12
17-
? (num % 12) + 'am'
18-
: (num % 12) + 'pm';
16+
? 12 + 'pm'
17+
: num < 12
18+
? (num % 12) + 'am'
19+
: (num % 12) + 'pm';
1920
```
2021

2122
```js

‎snippets/join.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ Omit the second argument, `separator`, to use a default separator of `','`.
1111
Omit the third argument, `end`, to use the same value as `separator` by default.
1212

1313
```js
14+
1415
const join = (arr, separator = ',', end = separator) =>
1516
arr.reduce(
1617
(acc, val, i) =>
1718
i === arr.length - 2
1819
? acc + val + end
1920
: i === arr.length - 1
20-
? acc + val
21-
: acc + val + separator,
21+
? acc + val
22+
: acc + val + separator,
2223
''
2324
);
2425
```

‎snippets/pipeAsyncFunctions.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Pr
1414
```
1515

1616
```js
17+
1718
const sum = pipeAsyncFunctions(
1819
x => x + 1,
1920
x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),
2021
x => x + 3,
2122
async x => (await x) + 4
2223
);
23-
(async () => {
24+
(async() => {
2425
console.log(await sum(5)); // 15 (after one second)
2526
})();
2627
```

‎test/_30s.js‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ const deepClone = obj => {
198198
return Array.isArray(obj) && obj.length
199199
? (clone.length = obj.length) && Array.from(clone)
200200
: Array.isArray(obj)
201-
? Array.from(obj)
202-
: clone;
201+
? Array.from(obj)
202+
: clone;
203203
};
204204
const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v)));
205205
const deepFreeze = obj =>
@@ -211,13 +211,13 @@ const deepMapKeys = (obj, f) =>
211211
Array.isArray(obj)
212212
? obj.map(val => deepMapKeys(val, f))
213213
: typeof obj === 'object'
214-
? Object.keys(obj).reduce((acc, current) => {
214+
? Object.keys(obj).reduce((acc, current) => {
215215
const val = obj[current];
216216
acc[f(current)] =
217217
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
218218
return acc;
219219
}, {})
220-
: obj;
220+
: obj;
221221
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
222222
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
223223
const degreesToRads = deg => (deg * Math.PI) / 180.0;
@@ -239,9 +239,9 @@ const dig = (obj, target) =>
239239
target in obj
240240
? obj[target]
241241
: Object.values(obj).reduce((acc, val) => {
242-
if (acc !== undefined) return acc;
243-
if (typeof val === 'object') return dig(val, target);
244-
}, undefined);
242+
if (acc !== undefined) return acc;
243+
if (typeof val === 'object') return dig(val, target);
244+
}, undefined);
245245
const digitize = n => [...`${n}`].map(i => parseInt(i));
246246
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
247247
const drop = (arr, n = 1) => arr.slice(n);
@@ -314,11 +314,11 @@ const extendHex = shortHex =>
314314
const factorial = n =>
315315
n < 0
316316
? (() => {
317-
throw new TypeError('Negative numbers are not allowed!');
318-
})()
317+
throw new TypeError('Negative numbers are not allowed!');
318+
})()
319319
: n <= 1
320-
? 1
321-
: n * factorial(n - 1);
320+
? 1
321+
: n * factorial(n - 1);
322322
const fibonacci = n =>
323323
Array.from({ length: n }).reduce(
324324
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
@@ -419,10 +419,10 @@ const getMeridiemSuffixOfInteger = num =>
419419
num === 0 || num === 24
420420
? 12 + 'am'
421421
: num === 12
422-
? 12 + 'pm'
423-
: num < 12
424-
? (num % 12) + 'am'
425-
: (num % 12) + 'pm';
422+
? 12 + 'pm'
423+
: num < 12
424+
? (num % 12) + 'am'
425+
: (num % 12) + 'pm';
426426
const getScrollPosition = (el = window) => ({
427427
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
428428
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
@@ -643,8 +643,8 @@ const join = (arr, separator = ',', end = separator) =>
643643
i === arr.length - 2
644644
? acc + val + end
645645
: i === arr.length - 1
646-
? acc + val
647-
: acc + val + separator,
646+
? acc + val
647+
: acc + val + separator,
648648
''
649649
);
650650
const JSONtoCSV = (arr, columns, delimiter = ',') =>

0 commit comments

Comments
 (0)