update name for external accumulator.

This commit is contained in:
taimoor
2020-09-22 17:37:22 +05:00
parent f3ddb653f0
commit 351ce48f64

View File

@ -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.
```js
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) {
return acc[e] || (acc[e] = isNaN(Number(keys[i + 1])) ? (keys.length - 1 === i ? obj[k] : {}) : []);
}, acc1)
return acc1;
}, res)
return res;
},{});
}
```