Lint pick, build README
This commit is contained in:
13
README.md
13
README.md
@ -457,18 +457,15 @@ const percentile = (arr, val) =>
|
||||
|
||||
### Pick
|
||||
|
||||
Use `.reduce()` to convert the filtered/picked keys back to a object with the corresponding key:value pair if the key exist in the obj.
|
||||
Use `Array.reduce()` to convert the filtered/picked keys back to a object with the corresponding key:value pair if the key exist in the obj.
|
||||
|
||||
```js
|
||||
const pick = (obj, arr) => arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {});
|
||||
|
||||
// const object = { 'a': 1, 'b': '2', 'c': 3 };
|
||||
// pick(object, ['a', 'c']) -> { 'a': 1, 'c': 3 }
|
||||
|
||||
const pick = (obj, arr) =>
|
||||
arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {});
|
||||
// pick({ 'a': 1, 'b': '2', 'c': 3 }, ['a', 'c']) -> { 'a': 1, 'c': 3 }
|
||||
// pick(object, ['a', 'c'])['a'] -> 1
|
||||
// pick(object, ['a', 'c'])['c'] -> 3
|
||||
|
||||
```
|
||||
|
||||
### Pipe
|
||||
|
||||
Use `Array.reduce()` to pass value through functions.
|
||||
|
||||
@ -1,14 +1,10 @@
|
||||
### Pick
|
||||
|
||||
Use `.reduce()` to convert the filtered/picked keys back to a object with the corresponding key:value pair if the key exist in the obj.
|
||||
Use `Array.reduce()` to convert the filtered/picked keys back to a object with the corresponding key:value pair if the key exist in the obj.
|
||||
|
||||
```js
|
||||
const pick = (obj, arr) => arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {});
|
||||
|
||||
// const object = { 'a': 1, 'b': '2', 'c': 3 };
|
||||
// pick(object, ['a', 'c']) -> { 'a': 1, 'c': 3 }
|
||||
|
||||
const pick = (obj, arr) =>
|
||||
arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {});
|
||||
// pick({ 'a': 1, 'b': '2', 'c': 3 }, ['a', 'c']) -> { 'a': 1, 'c': 3 }
|
||||
// pick(object, ['a', 'c'])['a'] -> 1
|
||||
// pick(object, ['a', 'c'])['c'] -> 3
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user