Travis build: 1019

This commit is contained in:
30secondsofcode
2019-02-25 06:42:36 +00:00
parent 067ad291d6
commit ffc7d2aeb8
24 changed files with 125 additions and 74 deletions

View File

@ -13,11 +13,11 @@ const deepMapKeys = (obj, f) =>
? obj.map(val => deepMapKeys(val, f))
: typeof obj === 'object'
? Object.keys(obj).reduce((acc, current) => {
const val = obj[current];
acc[f(current)] =
const val = obj[current];
acc[f(current)] =
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
return acc;
}, {})
return acc;
}, {})
: obj;
```

View File

@ -10,9 +10,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);
```
```js

View File

@ -11,8 +11,8 @@ 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);

View File

@ -10,6 +10,5 @@ const mapNumRange = (num, inMin, inMax, outMin, outMax) =>
```
```js
mapNumRange(5, 0, 10, 0, 100); // 50
```

View File

@ -11,13 +11,14 @@ const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Pr
```
```js
const sum = pipeAsyncFunctions(
x => x + 1,
x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),
x => x + 3,
async x => (await x) + 4
);
(async () => {
(async() => {
console.log(await sum(5)); // 15 (after one second)
})();
```

View File

@ -6,12 +6,13 @@ Use `Array.prototype.filter()` to find array elements that return truthy values
The `func` is invoked with three arguments (`value, index, array`).
```js
const remove = (arr, func) =>
Array.isArray(arr)
? arr.filter(func).reduce((acc, val) => {
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
: [];
```

View File

@ -7,7 +7,9 @@ Use `Array.prototype.reduce()`, `Math.pow()` and `Math.sqrt()` to calculate the
```js
const vectorDistance = (...coords) => {
let pointLength = Math.trunc(coords.length / 2);
let sum = coords.slice(0, pointLength).reduce((acc, val, i) => acc + (Math.pow(val - coords[pointLength + i], 2)), 0);
let sum = coords
.slice(0, pointLength)
.reduce((acc, val, i) => acc + Math.pow(val - coords[pointLength + i], 2), 0);
return Math.sqrt(sum);
};
```