update name for external accumulator.
This commit is contained in:
@ -11,11 +11,11 @@ Unflatten an object with the paths for keys.
|
|||||||
- Otherwise, add the appropriate key-value pair to the accumulator object and return value as the accumulator.
|
- Otherwise, add the appropriate key-value pair to the accumulator object and return value as the accumulator.
|
||||||
```js
|
```js
|
||||||
const unflattenObject = obj =>{
|
const unflattenObject = obj =>{
|
||||||
return Object.keys(obj).reduce((acc1 , k)=>{
|
return Object.keys(obj).reduce((res , k)=>{
|
||||||
k.split('.').reduce(function(acc, e, i , keys) {
|
k.split('.').reduce(function(acc, e, i , keys) {
|
||||||
return acc[e] || (acc[e] = isNaN(Number(keys[i + 1])) ? (keys.length - 1 === i ? obj[k] : {}) : []);
|
return acc[e] || (acc[e] = isNaN(Number(keys[i + 1])) ? (keys.length - 1 === i ? obj[k] : {}) : []);
|
||||||
}, acc1)
|
}, res)
|
||||||
return acc1;
|
return res;
|
||||||
},{});
|
},{});
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user