run linter
This commit is contained in:
@ -7,12 +7,14 @@ Get the object's keys with `Object.keys()` and return an object with the new key
|
|||||||
The initial value is an empty object which is used as the accumulator, `acc`, in the callback function. Using the spread operator `(...)`, `acc` is continuously merged with a new object containing the new key and original object's value. If a new key doesn't exist, fallback to original object's key.
|
The initial value is an empty object which is used as the accumulator, `acc`, in the callback function. Using the spread operator `(...)`, `acc` is continuously merged with a new object containing the new key and original object's value. If a new key doesn't exist, fallback to original object's key.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const renameKeys = (keysMap, obj) => Object
|
const renameKeys = (keysMap, obj) =>
|
||||||
.keys(obj)
|
Object.keys(obj).reduce(
|
||||||
.reduce((acc, key) => ({
|
(acc, key) => ({
|
||||||
...acc,
|
...acc,
|
||||||
...{ [keysMap[key] || key]: obj[key] }
|
...{ [keysMap[key] || key]: obj[key] }
|
||||||
}), {});
|
}),
|
||||||
|
{}
|
||||||
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user