Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -35,6 +35,7 @@ const httpPost = (url, callback, data = null, err = console.error) => {
|
||||
|
||||
|
||||
|
||||
|
||||
const newPost = {
|
||||
"userId": 1,
|
||||
"id": 1337,
|
||||
|
||||
@ -7,9 +7,12 @@ Use `Array.reduce()` to create a new object with the same values and mapped keys
|
||||
|
||||
```js
|
||||
const mapKeys = (obj, fn) =>
|
||||
Object.keys(obj).reduce((acc,k) => {acc[fn(obj[k], k, obj)] = obj[k]; return acc;},{});
|
||||
Object.keys(obj).reduce((acc, k) => {
|
||||
acc[fn(obj[k], k, obj)] = obj[k];
|
||||
return acc;
|
||||
}, {});
|
||||
```
|
||||
|
||||
```js
|
||||
mapKeys({ 'a': 1, 'b': 2 }, (val, key) => key + val); // { a1: 1, b2: 2 }
|
||||
mapKeys({ a: 1, b: 2 }, (val, key) => key + val); // { a1: 1, b2: 2 }
|
||||
```
|
||||
|
||||
@ -7,13 +7,16 @@ Use `Array.reduce()` to create a new object with the same keys and mapped values
|
||||
|
||||
```js
|
||||
const mapValues = (obj, fn) =>
|
||||
Object.keys(obj).reduce((acc,k) => {acc[k] = fn(obj[k], k, obj); return acc;},{});
|
||||
Object.keys(obj).reduce((acc, k) => {
|
||||
acc[k] = fn(obj[k], k, obj);
|
||||
return acc;
|
||||
}, {});
|
||||
```
|
||||
|
||||
```js
|
||||
const users = {
|
||||
'fred': { 'user': 'fred', 'age': 40 },
|
||||
'pebbles': { 'user': 'pebbles', 'age': 1 }
|
||||
fred: { user: 'fred', age: 40 },
|
||||
pebbles: { user: 'pebbles', age: 1 }
|
||||
};
|
||||
mapValues(users, u => u.age); // { fred: 40, pebbles: 1 }
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user