Travis build: 1012
This commit is contained in:
@ -339,6 +339,7 @@
|
|||||||
<li><a tags="math,beginner,intermediate" href="./math#isprime">isPrime</a></li>
|
<li><a tags="math,beginner,intermediate" href="./math#isprime">isPrime</a></li>
|
||||||
<li><a tags="math,recursion,beginner" href="./math#lcm">lcm</a></li>
|
<li><a tags="math,recursion,beginner" href="./math#lcm">lcm</a></li>
|
||||||
<li><a tags="math,utility,advanced" href="./math#luhncheck">luhnCheck</a></li>
|
<li><a tags="math,utility,advanced" href="./math#luhncheck">luhnCheck</a></li>
|
||||||
|
<li><a tags="math,beginner" href="./math#mapnumrange">mapNumRange</a></li>
|
||||||
<li><a tags="math,array,function,beginner" href="./math#maxby">maxBy</a></li>
|
<li><a tags="math,array,function,beginner" href="./math#maxby">maxBy</a></li>
|
||||||
<li><a tags="math,array,intermediate" href="./math#median">median</a></li>
|
<li><a tags="math,array,intermediate" href="./math#median">median</a></li>
|
||||||
<li><a tags="math,array,beginner" href="./math#midpoint">midpoint</a></li>
|
<li><a tags="math,array,beginner" href="./math#midpoint">midpoint</a></li>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -339,6 +339,7 @@
|
|||||||
<li><a tags="math,beginner,intermediate" href="./math#isprime">isPrime</a></li>
|
<li><a tags="math,beginner,intermediate" href="./math#isprime">isPrime</a></li>
|
||||||
<li><a tags="math,recursion,beginner" href="./math#lcm">lcm</a></li>
|
<li><a tags="math,recursion,beginner" href="./math#lcm">lcm</a></li>
|
||||||
<li><a tags="math,utility,advanced" href="./math#luhncheck">luhnCheck</a></li>
|
<li><a tags="math,utility,advanced" href="./math#luhncheck">luhnCheck</a></li>
|
||||||
|
<li><a tags="math,beginner" href="./math#mapnumrange">mapNumRange</a></li>
|
||||||
<li><a tags="math,array,function,beginner" href="./math#maxby">maxBy</a></li>
|
<li><a tags="math,array,function,beginner" href="./math#maxby">maxBy</a></li>
|
||||||
<li><a tags="math,array,intermediate" href="./math#median">median</a></li>
|
<li><a tags="math,array,intermediate" href="./math#median">median</a></li>
|
||||||
<li><a tags="math,array,beginner" href="./math#midpoint">midpoint</a></li>
|
<li><a tags="math,array,beginner" href="./math#midpoint">midpoint</a></li>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -8,17 +8,16 @@ 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;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -6,14 +6,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
|
||||||
|
|||||||
@ -8,12 +8,11 @@ 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);
|
||||||
|
|||||||
@ -5,9 +5,11 @@ Maps a number from one range to another range.
|
|||||||
Returns `num` mapped between `outMin`-`outMax` from `inMin`-`inMax`.
|
Returns `num` mapped between `outMin`-`outMax` from `inMin`-`inMax`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const mapNumRange = (num, inMin, inMax, outMin, outMax) => (num - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
const mapNumRange = (num, inMin, inMax, outMin, outMax) =>
|
||||||
|
((num - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
mapNumRange(5,0,10,0,100); // 50
|
|
||||||
|
mapNumRange(5, 0, 10, 0, 100); // 50
|
||||||
```
|
```
|
||||||
|
|||||||
@ -11,14 +11,13 @@ 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)
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
|
|||||||
@ -6,13 +6,12 @@ Use `Array.prototype.filter()` to find array elements that return truthy values
|
|||||||
The `func` is invoked with three arguments (`value, index, array`).
|
The `func` is invoked with three arguments (`value, index, array`).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
const remove = (arr, func) =>
|
const remove = (arr, func) =>
|
||||||
Array.isArray(arr)
|
Array.isArray(arr)
|
||||||
? arr.filter(func).reduce((acc, val) => {
|
? arr.filter(func).reduce((acc, val) => {
|
||||||
arr.splice(arr.indexOf(val), 1);
|
arr.splice(arr.indexOf(val), 1);
|
||||||
return acc.concat(val);
|
return acc.concat(val);
|
||||||
}, [])
|
}, [])
|
||||||
: [];
|
: [];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
1045
test/_30s.js
1045
test/_30s.js
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user