Lint pick, build README

This commit is contained in:
Angelos Chalaris
2017-12-14 01:34:24 +02:00
parent 6feed83f82
commit e7252bb7de
2 changed files with 10 additions and 17 deletions

View File

@ -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.

View File

@ -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
```
```